URL Rewrite - Query String

前端 未结 2 1180
暖寄归人
暖寄归人 2021-01-15 03:18

I have a news (blog) site that returns urls in the following format when individual posts are selected:

website.net/sitenews.php?q=posts/view/postname/12
         


        
2条回答
  •  粉色の甜心
    2021-01-15 03:59

    Try this instead in your .htaccess:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^q=(.*)$ [NC]
    RewriteRule ^(.*)$ /$1/%1? [R=301,L,NE]
    
    R=301 will redirect with https status 301
    L will make last rule
    NE is for no escaping query string
    
    %1 is capture group for query string q= (whatever comes after q=)
    $1 is your REQUEST_URI
    

提交回复
热议问题