Jump to content

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:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.