Remove page + query string from URL

2019-07-25 12:24发布

I have an old URL syntax and since I changed my CMS, the old syntax doesn't work anymore and I have a lot of error 404. I want to delete "article.php?p=" here :

to :

How can I totally remove the string "article.php?p=" from my URLs with htaccess please ? I tried a lot of things but it seems too difficult for me.

2条回答
疯言疯语
2楼-- · 2019-07-25 12:55

To redirect the old URL to the new one, you must first capture the page's name from the query string with RewriteCond and then use this in RewriteRule

RewriteCond &%{QUERY_STRING}& &p=(.*?)&
RewriteRule ^article\.php$ /%1? [R,L]
查看更多
疯言疯语
3楼-- · 2019-07-25 13:01

To remove article.php?p= use the following:

RewriteEngine On
RewriteRule ^([^/]*)\.php$ /article.php?p=$1 [L]

You can use this as an alternative:

RewriteCond %{QUERY_STRING} (^|&)p=name_of_my_page($|&)
RewriteRule ^article\.php$ /name_of_my_page?&%{QUERY_STRING}
查看更多
登录 后发表回答