remove query string from end of URL using .htaccess

后端 未结 2 1117
攒了一身酷
攒了一身酷 2020-12-06 13:53

I\'m trying to remove string from the end of URL:

For example i have a structure like this:

http://sitename.com/category/first-category-name/?post_ty         


        
相关标签:
2条回答
  • 2020-12-06 14:10

    it's simple, just use:

    RewriteCond %{QUERY_STRING}    "post_type=" [NC]
    RewriteRule (.*)  /$1? [R=301,L]
    

    If you are going add this to wordpress website, you need add it before any wordpress rules:

    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    

    but after

    RewriteBase /
    
    0 讨论(0)
  • 2020-12-06 14:19

    Just do something like this:

    RewriteEngine On
    RewriteBase /
    # Make sure there is a query string
    RewriteCond %{QUERY_STRING} .
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .*  /? [R=301,L]
    

    Place a ? at the end to remove the query when present.

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