简体   繁体   English

htaccess网址重写无法正常工作

[英]Htaccess url rewrite not working correctly

I have an issue with url rewriting, here's what I have so far: 网址重写存在问题,这是到目前为止的内容:

        Options +FollowSymlinks
        RewriteEngine on
        RewriteRule \.(gif|png|jpg|css|js)$|^index\.php$ - [L]
        RewriteRule ^users/(.+)$ /profile.php?userid=$1 [NC]
        RewriteRule ^(.+)/(.+)$ /main.php?region=$1&place=$2 [NC]

Basically, if the url is mysite.com/users/username I want it to use profile.php, then for anything else, to go to main.php. 基本上,如果url是mysite.com/users/username,我希望它使用profile.php,那么对于其他任何事情,请转至main.php。

However, with that code it doesn't happen as expected, it always uses main.php. 但是,使用该代码并不会按预期发生,而是始终使用main.php。 Is there anyway you can use if and elses in htaccess, or something similar? htaccess中是否可以使用if和else或类似的东西?

You're missing L flag from 2nd and 3rd rules. 您缺少第二条和第三条规则中的L标志。 Have your code like this: 有这样的代码:

RewriteRule \.(gif|png|jpg|css|js)$|^index\.php$ - [L]
RewriteRule ^users/(.+)$ /profile.php?userid=$1 [NC,L,QSA]
RewriteRule ^(.+)/(.+)$ /main.php?region=$1&place=$2 [NC,L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM