Redirecting from a dynamic URL to a prettier/simple URL?

Redirecting from a dynamic URL to a prettier/simple URL? - .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, redirects, , , .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 :


I am trying to redirect a page via my .htaccess, but it does not seem to be working.



Old page:
/dyn/?q=customer%20reference&f=1,1,1,1,1,1&c=10,10,10,10,10,10&s=1,1,1,1,1,1,1&st=1



New page:
/customer-references/



So it should be as simple as this:



RewriteEngine On
RewriteCond %QUERY_STRING ^q=customer(?:[ +]|%20)reference&f=1$ [NC]
RewriteRule ^dyn/$ /1? [R=301,NE,NC,L]


But it does not seem to be working. Is it because the original page's dynamic URL?



The new page is actually a different physical php page if that matters.



BTW, I also tried a straight 301 Redirect in the .htaccess. That didn't seem to work either:



redirect 301 /dyn/?q=customer%20reference&f=1,1,1,1,1,1&c=10,10,10,10,10,10&s=1,1,1,1,1,1,1&st=1 /customer-references/


And another failed attempt was this:



RewriteCond %QUERY_STRING ^customer%20reference&f=1,1,1,1,1,1&c=10,10,10,10,10,10&s=1,1,1,1,1,1,1&st=1$
RewriteRule ^$ http://www.domain.com/customer-references/? [R=301,L]


Am I making this more difficult than it needs to be?


Solution :

This did it, though I can't take credit for finding the solution on my own. Sister site stackoverflow offered up the proper code for .htaccess



RewriteCond %QUERY_STRING  ^q=customer%20reference&f= [NC]
RewriteRule ^dyn/$ /customer-references/? [L,R=301]

Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect