cyberRobot Posted April 20, 2010 Share Posted April 20, 2010 How do I set up a 301 redirects in my .htaccess file so that a folder reference get sent to a specific file. Without it trying to redirect all the files within that folder. For example, if I have a link like: http://www.example.com/about_us_page/index.html and want to redirect it to: http://www.example.com/about/ I would normally create a couple statements like this: redirect 301 /about_us_page/index.html http://www.example.com/about/ redirect 301 /about_us_page/ http://www.example.com/about/ The problem is that second statement also redirects everything within the "about_us_page" to the new "about" folder occasionally resulting in a 404 error. Is there a way to indicate that the "/about_us_page/" part only refers to the folder reference. I want it to treat the following senarios the same: http://www.example.com/about_us_page/index.html http://www.example.com/about_us_page/ http://www.example.com/about_us_page Where if someone types: http://www.example.com/about_us_page/non_existant_page.html It doesn't get redirected to: http://www.example.com/about/non_existant_page.html Link to comment https://forums.phpfreaks.com/topic/199169-help-with-htaccess-to-redirect-folder-references/ Share on other sites More sharing options...
cyberRobot Posted April 20, 2010 Author Share Posted April 20, 2010 OK, nevermind The answer is to use redirectMatch: redirectMatch 301 ^/about_us_page/$ http://www.example.com/about/ redirectMatch 301 ^/about_us_page$ http://www.example.com/about/ This will force an exact match. Why is it that I can never find a solution until I attempt to ask someone else! I've been looking for this solution for quite some time now. O' well...another unknown that I can check off my list. Link to comment https://forums.phpfreaks.com/topic/199169-help-with-htaccess-to-redirect-folder-references/#findComment-1045363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.