2011-10-19 66 views
2

我試圖讓我的網址看在我的網站上特定的子目錄漂亮通過重寫改變:
www.example.com/sub/file/{some_number}/內部 到:
www.example.com/sub/file.php?var={some_number}
我不斷收到404 。 我使用.htaccess文件看起來像這樣已經開始轉移我的網站php擴展:的.htaccess URL重寫與變量

RewriteEngine on 
# 
## Internally rewrite extensionless file requests to .php files ## 
# 
# If the requested URI does not contain a period in the final path-part 
RewriteCond %{REQUEST_URI} !(\.[^./]+)$ 
# and if it does not exist as a directory 
RewriteCond %{REQUEST_FILENAME} !-d 
# and if it does not exist as a file 
RewriteCond %{REQUEST_FILENAME} !-f 
# then add .php to get the actual filename 
RewriteRule (.*) /$1.php [L] 
# 
## Externally redirect clients directly requesting .html page URIs to extensionless URIs 
# 
# If client request header contains html file extension 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP 
# externally redirect to extensionless URI 
RewriteRule ^(.+)\.html$ http://www.dirtycoffee.com/$1 [R=301,L] 

# If client request header contains php file extension 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP 
# externally redirect to extensionless URI 
RewriteRule ^(.+)\.php$ http://www.dirtycoffee.com/$1 [R=301,L] 

我現在的嘗試是在像頂部添加一行:

#Subdirectory rewrite: 
RewriteRule ^sub/file/([0-9]+)/?$ sub/file?num=$1 [L] # Handle requests for file 

我知道我必須有衝突的規則,但我認爲[L]會停止,如果新規則被應用。

回答

1

相反的:

RewriteRule ^sub/file/([0-9]+)/?$ sub/file?num=$1 [L] 

嘗試:

RewriteRule ^sub/file/([0-9]+)/?$ /sub/file.php?num=$1 [L] 

你是正確的,[L]將停止處理規則,但是這也意味着你不能消除,因爲php擴展規則是低於這一個。另請注意主導斜線。

+0

這樣做!非常感謝!我一直盯着這種方式太久了。另外(Google員工的注意事項)不得不將鏈接更新到我的CSS表格,因爲該頁面將其視爲目錄更改。 – chris