douliangbian7323 2013-07-06 17:35
浏览 24
已采纳

如何.htaccess重定向到www而不会失去GET

need some help. i have:

RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^catalog/ catalog.php
RewriteRule ^catalog/(.*)/ catalog.php?id=$1

with this redirect i don't receive (http://www.example.com/catalog/abc/)

GET['id']

how to receive GET['id']?

  • 写回答

1条回答 默认 最新

  • drrhr20884 2013-07-06 17:48
    关注

    Your 2nd rule needs 2 flags:

    • QSA - Query String Append
    • L - Last

    Overall your .htaccess should look like this:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^example\.com$
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    RewriteRule ^catalog/([^/]+)/?$ catalog.php?id=$1 [L,QSA,NC]
    

    QSA flag in 2nd rule will make sure to presserve any existing query string while adding a new query parameter id

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?