【问题标题】:I can't figure out why my url rewrite isn't working我不知道为什么我的 url 重写不起作用
【发布时间】:2011-02-08 10:10:34
【问题描述】:

大家好。 我是 url 重写的新手,但我似乎无法弄清楚为什么这不起作用

我有链接:http://thoughtsmash.com/profile.php?name=1

我想改写成:http://thoughtsmash.com/profilename/1

我的 .htaccess 文件中有这个:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
RewriteRule ^/profilename/([0-9_]+)$ /profile.php?name=$1 [NC]

但它什么也没做!删除“www”。工作正常,但其余的没有。关于为什么的任何想法?谢谢

【问题讨论】:

    标签: php .htaccess mod-rewrite web


    【解决方案1】:

    试试这个:

    Options +FollowSymlinks
    RewriteEngine on
    
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
    
    RewriteRule ^profilename/([0-9_]+)$ /profile.php?name=$1 [NC]
    

    请注意,我添加了 RewriteBase 并删除了前导 /

    【讨论】:

    • 感谢您的回复,不幸的是它仍然没有改变任何东西。
    • 好的,感谢您的帮助。对为什么它在我的情况下不起作用有任何想法吗?
    • @user607436:不,它应该可以工作。对于这种微不足道的规则,我认为没有任何失败的可能性。
    • 解决了!对我来说有些愚蠢... :D 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2016-08-25
    • 2021-11-16
    • 2021-04-09
    • 2020-09-19
    • 2014-01-17
    • 2013-11-27
    • 1970-01-01
    • 2019-05-27
    相关资源
    最近更新 更多