Jump to content

Help with .htaccess to redirect folder references


cyberRobot

Recommended Posts

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

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.  :shrug:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.