.htaccess Rewrite whole dir contents to another

.htaccess Rewrite whole dir contents to another - .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, url-rewriting, nginx, , .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 rewrite the whole contents of a directory to the home url.



so, if someone visits www.example.com/bnn27sh32j@d299/gold it should take them to www.example.com/gold



I have tried:



RewriteRule ^bnn27sh32j@d299/(.*)$ /$1 [R=301,NC,L]


doesnt work, maybe its because it has the illegal characters in the dir name?


Solution :

Try this:



RedirectMatch 301 ^/bnn27sh32j@d299/(.*) http://www.example.com/$1


It takes http://www.example.com/bnn27sh32j@d299/gold and redirects to http://www.example.com/gold.



Before implementing, you can test the rule here: https://htaccess.mwl.be/


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