| :: |
| Author |
Message |
ebnx
Joined: 01 Nov 2007 Posts: 21
|
Posted: Sat Nov 24, 2007 6:39 am Post subject: 301 redirect entire subdirectory to a single page |
|
|
Folks:
I'm interested in 301 redirecting all pages in a subdirectory of my website to a single page off of the root directory. To illustrate:
I want all pages in: -http://www.website.com/sub/
To be 301 redirected to: -http://www.website.com/page.html
I thought I could do it by adding the following command to my .htaccess file:
Redirect 301 /sub -http://www.website.com/page.html
But it doesn't seem to be working. Anyone have any advice on what I should be putting into my .htaccess?
The RewriteEngine is turned on, and I've been able to 301 redirect other pages in the past.
Thanks for your help! |
|
|
| Back to top |
|
 |
|
 |
SeO Administrateur - Site Admin

Joined: 15 Mar 2006 Posts: 3477
|
|
| Back to top |
|
 |
ebnx
Joined: 01 Nov 2007 Posts: 21
|
Posted: Sat Nov 24, 2007 9:25 pm Post subject: Re: 301 redirect entire subdirectory to a single page |
|
|
Thanks SeO!
Someone else had also suggested that I use the following in my .htaccess to achieve the same 301-redirect result:
| Code: | | RedirectMatch 301 ^/sub(.*)$ http://www.website.com/page.html |
Do you have any thoughts on whether one is more appropriate/effective than the other?
Thanks again! |
|
|
| Back to top |
|
 |
Peter77 phpBB SEO Team


Joined: 10 May 2006 Posts: 512 Location: Michigan
|
Posted: Sat Nov 24, 2007 11:41 pm Post subject: Re: 301 redirect entire subdirectory to a single page |
|
|
| I think the one SeO has given you is probably more efficient since it is using the L rule ( last rule ) so that it stops searching for more to rewrite -- it doesn't go any further then it needs too... so probably saving server resources. |
|
|
| Back to top |
|
 |
ebnx
Joined: 01 Nov 2007 Posts: 21
|
Posted: Sat Nov 24, 2007 11:54 pm Post subject: Re: 301 redirect entire subdirectory to a single page |
|
|
| Thanks for that tip, Peter! |
|
|
| Back to top |
|
 |
ebnx
Joined: 01 Nov 2007 Posts: 21
|
Posted: Sun Nov 25, 2007 8:11 am Post subject: Re: 301 redirect entire subdirectory to a single page |
|
|
I'm encountering a strange issue with the 301 redirect.
As I said before, I wanted all pages in a specific subdirectory:
-http://www.website.com/sub/
To redirect to a specific page:
-http://www.website.com/page.html
The strange thing that is happening is that several of the pages in the subdirectory have weird php URLs like:
-http://www.website.com/sub/example.php?id=section1
And using SeO's .htaccess directive, they are being redirected/rewritten as
-http://www.website.com/page.html?id=section
Anyone have any thoughts on how I can get rid of the "?id=section1" part?
Thanks very much! |
|
|
| Back to top |
|
 |
dcz Administrateur - Site Admin

Joined: 28 Apr 2006 Posts: 14403
|
|
| Back to top |
|
 |
ebnx
Joined: 01 Nov 2007 Posts: 21
|
Posted: Sun Nov 25, 2007 11:51 pm Post subject: Re: 301 redirect entire subdirectory to a single page |
|
|
I found a solution from another forum:
| Quote: |
This would likely be a code-order problem, where the internal rewrite of the static URL to the 'weird' dynamic URL is occurring before the external redirect.
In order to control the order of execution you will need to use the mod_rewrite version of the redirect, and place the redirect ahead of the internal rewrite. Further, you'll want to clear any query string received with the client request:
RewriteRule ^sub/ /page.html? [R=301,L]
I assume that you already have other working RewriteRules. If not, you will need to 'set up' mod_rewrite by putting the following code before your first RewriteCond or RewriteRule:
Options +FollowSymLinks
RewriteEngine on
The Options directive may not be allowed on your server, but if it is allowed, it may be required. There is no way to tell except to try it. If it is not allowed and also required, then you won't be able to use mod_rewrite on your server. |
Thanks! |
|
|
| Back to top |
|
 |
|
|