Home > database >  301 Redirect in htaccess for URLs having Parameter P
301 Redirect in htaccess for URLs having Parameter P

Time:08-30

I need to set 301 redirect in htaccess for URLs having parameter P. One example URL is http://www.price4india.co.in/vivo-x20-plus-ud-price-in-india-scanner-feature-real.html?p=1028 to http://www.price4india.co.in/vivo-x20-plus-ud-price-in-india-scanner-feature-real.html

After redirect everything after .html shall get removed and the value after P=...... can be any numerical value. So far I have tried below query but its not working. Any suggestion please...

RewriteCond %{QUERY_STRING} ^p(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L]

CodePudding user response:

With your shown samples, please try following .htaccess rules file. Make sure to keep your .html file and .htaccess files in root path only.

Make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(.*\.html)\?p=\d \s [NC]
RewriteRule ^ /%1? [R=301,L]

NOTE: In case you have further more rules in your .htaccess rules, which includes internal rewrite of html files then you could keep these rules above those.

  • Related