我在htaccess文件中使用此代码:
# 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 Page Not Found
答案 0 :(得分: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]
答案 1 :(得分: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]
同时确保以下内容;
AllowOverride
设置为ALL