Deprecating old URLs using htaccess
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, , , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :Currently I have this in my htaccess file:
RewriteEngine on
RewriteRule ^chart-(.*).php$ ./keyboard-chart.php?seo=$1 [QSA]
RewriteRule ^keyboard-diagram-(.*).php$ ./keyboard-chart.php?seo=$1 [QSA]
However, I would like to deprecate line 2, so that something like this happens instead:
Whatever ^chart-(.*).php$ ./keyboard-diagram-$1.php
E.g. I want the keyboard-diagram-$1.php URL to appear in the browser address bar. But I don't know the correct syntax. How do I properly implement this behavior? Thanks.
You have a choice, whether to offer a permanent redirect or, a temporary one. Probably you want to make it permanent. There is a good explanation of why on Stack Overflow here.
Currently, you are rewriting the URL internally but what you need to do is to have the browser load the new resource actually.
RewriteRule ^chart-(.*).php$ ./keyboard-diagram-$1.php [R=301,L]
I presume what you posted was already working on your server, on my server it doesn't redirect correctly without dropping the '.'
RewriteRule ^chart-(.*).php$ ./keyboard-diagram-$1.php [R=301,L]
^
It might be worth setting [R=302,L] until you finish testing. If you use 301 and it is not doing what you want AND if your browser/any proxy remembers it can be a real pain to test. If there is even a slim possibility that the redirect may change in future you should stick with 302 - remember, 301 means permanent and really means it.
EDIT: I will write this in a more complete manner
RewriteEngine on
RewriteBase / #On some hosts this additional line is necessary and it is *possible* that it may need to be a path on some weird hosts or configurations
RewriteRule ^chart-(.*).php$ ./keyboard-diagram-$1.php [R=301,L]
# On the above line you may ^ need to remove the dot indicated - didn't work correctly on my test with it in place.
Comments
Post a Comment