URL Rewrite - Query String

前端 未结 2 1160
暖寄归人
暖寄归人 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:55

    If you are using any CMS, like wordpress, or joomla or SE, then you have option to do that else you need to have an .htaccess file where you can write the code, refer this links

    http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html

    http://www.webmasterworld.com/forum92/2545.htm

    http://www.google.com/#sclient=psy&hl=en&q=htaccess+change+the+url&aq=0p&aqi=p-p1g4&aql=&oq=htaccess+&pbx=1&bav=on.2,or.r_gc.r_pw.&fp=c875dd2b8adea15a

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题