2011-09-25 23 views
2

我的mod_rewriting似乎被我的.htaccess文件末尾的這一行搞砸了,而且我不能爲我的生活找出原因。mod_rewrite,在改變時不重寫

RewriteEngine ON 
Options FollowSymLinks 

# User profile with username specified 
RewriteRule ^([a-z0-9_.-]{1,30}+)$ profile.php?username=$1 [NC,L] 

我想匹配的用戶名,但讓他們有A-Z 0-9(任何情況下),也允許下劃線,點和連字符。

它工作正常,沒有

我試圖逃避他們太「_.-」,但無濟於事。

編輯:

這似乎與改寫的問題,是它導致我「styles.css的」文件被改寫,即使我有它設置爲不能重寫,如果文件或目錄存在。

這裏是整個.htaccess文件...

RewriteEngine ON 
Options FollowSymLinks 

# Only rewrite for folders and directories that don't exist 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# Remove www. 
RewriteCond %{HTTP_HOST} ^www.nitpicker.me$ [NC] 
RewriteRule ^(.*)$ http://nitpicker.me/$1 [R=301] 

# Remove the trailing slash if there is one 
RewriteRule ^(.+)/$ $1 

# Main pages 
RewriteRule ^(stream|settings|comment|profile)(.php)?$ $1.php [QSA,L] 

# Find friends page 
RewriteRule ^friends$ findfriends.php [L] 

RewriteRule ^subject-([0-9]+)$ page.php?subject_id=$1 [QSA,L] 
RewriteRule ^nit-([0-9]+)$ comment.php?nit_id=$1 

RewriteRule ^search-([a-z0-9]+)$ search.php?term=$1 [NC,L] 

# The initial sign up page with invite code 
RewriteRule ^signup(-([a-z0-9]+))?$ signup.php?invite=$2 [NC,L] 

# Trending page 
RewriteRule ^(newest|trending|most_picked) trending.php?select=$1 [QSA,L] 

# User profile with username specified 
RewriteRule ^([a-z0-9\-_\.]{1,30}+)$ profile.php?username=$1 [NC,L] 

我怎樣才能得到它停止它重寫我的「/styles.css」文件?

+0

我很驚訝,它曾經匹配;所有的請求將以「/」開頭,你明確排除。有時啓用重寫日誌('RewriteLog On'和'RewriteLogLevel'設置爲'5')將有助於診斷問題。 – larsks

+0

如果這就是你的意思,訪問文件會從URL中去掉尾隨的斜槓。所以nitpicker.me /只是nitpicker.me – Luke

+0

我期望mod_rewrite做一些日誌,你可以檢查? –

回答

3

使用本:

# User profile with username specified 
RewriteCond %{REQUEST_URI} !^.*\.css.*$ [NC] 
RewriteRule ^([a-z0-9\-_\.]{1,30}+)$ profile.php?username=$1 [NC,L] 
+0

謝謝你的寫作,我發現重寫的問題在於它由於重寫而打破了我的styles.css頁面。請參閱編輯。 – Luke

+0

好的,查看我更新的答案 –