【问题标题】:Htaccess url rewrite not working correctlyHtaccess url重写无法正常工作
【发布时间】:2012-10-31 20:18:14
【问题描述】:

我遇到了 url 重写的问题,这是我目前遇到的问题:

        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]

基本上,如果 url 是 mysite.com/users/username 我希望它使用 profile.php,然后其他任何东西,去 main.php。

但是,使用该代码并没有按预期发生,它始终使用 main.php。无论如何你可以在 htaccess 中使用 if 和 elses 或类似的东西吗?

【问题讨论】:

    标签: .htaccess url redirect


    【解决方案1】:

    第二条和第三条规则中缺少L 标志。有这样的代码:

    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]
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 2017-08-08
    • 2011-05-15
    • 2014-08-25
    相关资源
    最近更新 更多