【发布时间】:2016-08-11 01:11:55
【问题描述】:
.htaccess 文件,代码如下
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^tag/([A-Za-z0-9_]+)$ hashtag.php?hashtag=$1
RewriteRule ^([A-Za-z0-9_]+)$ profile.php?username=$1
在 nginx 重写中,我是这样设置的
location / {
if (!-e $request_filename){
rewrite ^/([A-Za-z0-9_]+)$ /profile.php?username=$1;
}
if (!-e $request_filename){
rewrite ^tag/([A-Za-z0-9_]+)$ /hashtag.php?hashtag=$1;
}
}
可以访问domain.com/hashtag.php?hashtag=123,domain.com/profile.php?username=name,也可以访问domain.com/name,但是不能访问domain.com /tag/123,它显示 404 错误。你能帮助我吗?非常感谢。
【问题讨论】:
-
也许你可以改变重写的顺序,把标签放在第一位:)?
-
@DusanBajic 也是同样的结果,404 错误。
标签: php apache .htaccess mod-rewrite nginx