Home > Net >  htaccess is working but does not replace the url
htaccess is working but does not replace the url

Time:03-16

I'm trying to modify the subdomain name in the URL to make it look nicer. My current URL look something like:

www.mystore.com/productInfo.php?cPath=11_11&productID=222

So, I want to make it nicer by Rewrite in .htaccess in main with this code:

RewriteEngine On    
RewriteRule ^productInfo/([0-9_-] )/([0-9_-] ) productInfo.php?cPath=$1&productID=$2 [NC,L]

When I run and test it on the URL by typing www.mystore.com/productInfo/11_11/222 in the URL it works well. However, when this page is redirected by a different page or is 'refreshed' with a self redirecting a href= link(in which the link is written in php by the previous programmer), the above old link is still visible in the URL instead of the new one.

I am still a beginner while I suspect that I might need to change something in the cPanel/Apache(I think) for this but currently, I am still do not have access to the cPanel control. Is there anything that I might have missed to write in the .htaccess file or I really do need the cPanel control or any other reasons?

Any help is appreciated. Sorry that I could not find similar questions on this.

CodePudding user response:

You can use the following :

RewriteEngine On
RewriteBase /

#redirect /productInfo.php?cPath=foo&productID=bar to /productInfo/foo/bar
RewriteCond %{THE_REQUEST} /productInfo\.php\?cPath=([0-9_-] )&productID=([0-9_-]) [NC]
RewriteRule ^ productInfo/%1/%2? [L,R=301]
#rewrite new URL to the old one
RewriteRule ^productInfo/([0-9_-] )/([0-9_-] ) productInfo.php?cPath=$1&productID=$2 [NC,L]
  • Related