Query string rewriting using .htaccess

后端 未结 2 863
-上瘾入骨i
-上瘾入骨i 2021-01-23 16:07

i am trying to rewrite a URL for SEO purpose.

The old URL is:

http://www.domain.net/index.php?p=beer

The new URL should be:

<         


        
相关标签:
2条回答
  • 2021-01-23 16:37

    Have you tried this:?

    ^([^/\.]+)\/?$
    

    Otherwise I would try the .htacces without the other stuff.

    Just:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^([^/\.]+)\/?$ index.php?p=$1
    
    0 讨论(0)
  • 2021-01-23 16:54

    If you want to capture part of the query string, you must use a RewriteCond with QUERY_STRING

    RewriteEngine On
    RewriteCond %{QUERY_STRING} p=(.+)
    RewriteRule ^/?index.php$ /%1? [R,L]
    

    This redirects the client to the new URL http://www.domain.net/beer.

    0 讨论(0)
提交回复
热议问题