2014-01-10 220 views
1

我在我的htaccess文件使用此代碼:htaccess的重寫規則重寫目錄/名稱的index.php ID

# Rewrites /blog/post-name-1 to be /index.php?post_name=post-name-1 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([a-zA-Z0-9-]+)/?$ /index.php?id=blog&post_name=$1 [L,QSA] 

我想重寫/blog/post-name-1/index.php?id=blog&post_name=post-name-1

但示出404未找到網頁

回答

1

認爲你需要按照覆蓋文件:

RewriteEngine On 
# Rewrites /blog/post-name-2 to be /index.php?post_name=post-name-2 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]*)/([^/]*)$ /index.php?id=$1&post_name=$2 [QSA,L] 
0

嘗試:

RewriteEngine On 
# Rewrites /blog/post-name-1 to be /index.php?post_name=post-name-1 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]*)$ /index.php?id=blog&post_name=$1 [QSA,L] 

也提供e確保以下內容;

  • 你允許的.htaccess是在httpd.conf中
  • 你已經設置AllowOverrideALL在httpd.conf