2014-09-01 74 views
1

因此,這裏是我的正則表達式不能在目錄重寫URL

Options -MultiViews 
DirectoryIndex index.php 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^article/([0-9]+)$ article.php?id=$1 [L,QSA,NC] 
RewriteRule ^site/(.*)$ site.php?id=$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC] 
RewriteRule ^(.+?)/?$ /$1.php [L] 

而這正是我希望我的URL看起來像:

http://localhost/developer/site/google.com 

所以我會做

RewriteRule ^site/(.*)$ site.php?id=$1 [L] 

但是當我去的網址,我所得到的全部是

未找到

在此服務器上找不到請求的URL /developer/site/google.com。

即使我在我的developer文件夾中有一個site.php。有任何想法嗎?

回答

1

假設您的htaccess位於developer文件夾中,您必須使用正確的路徑進行重寫(RewriteBase)。

同時,請不要忘記,RewriteCond是下一個RewriteRule

Options -MultiViews 

RewriteEngine On 
RewriteBase /developer/ 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^article/([0-9]+)$ article.php?id=$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^site/([^/]+)$ site.php?id=$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/developer/$1\.php -f [NC] 
RewriteRule ^(.+?)/?$ $1.php [L]