phpBB SEO
Boards
Directory  
SEO  
Downloads
  phpBB SEO : Search Engine Optimization, Directory, Forums  
Index
Forums
Annuaire
Référencement
Télécharger
 
  Search Rechercher
    Register
Username :  Password :  Log me on automatically each visit  
S'enregistrer  
 
   
301 redirect entire subdirectory to a single page

 
Post new topic   Reply to topic    phpBB SEO » SEO Forum  » Apache mod Rewrite
::  
Author Message
ebnx



Joined: 01 Nov 2007
Posts: 21

301 redirect entire subdirectory to a single pagePosted: 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
Administrateur - Site Admin


Joined: 15 Mar 2006
Posts: 3477

301 redirect entire subdirectory to a single pagePosted: Sat Nov 24, 2007 1:01 pm    Post subject: Re: 301 redirect entire subdirectory to a single page

You could use :

Code:
ReWriteRule ^dir/.*$ /location-where-to-go.html [L,R=301]


Right after the www prefix redirection in case you're using it (which you should), eg before the phpBB rewriterules.

_________________
phpBB SEO || SEO Forum || Forum Référencement
GYM Sitemap & RSS for phpBB3 has been released ! || GYM Sitemap & RSS for phpBB3 est disponible !
Back to top
ebnx



Joined: 01 Nov 2007
Posts: 21

301 redirect entire subdirectory to a single pagePosted: 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
phpBB SEO Team


Joined: 10 May 2006
Posts: 512
Location: Michigan

301 redirect entire subdirectory to a single pagePosted: 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

301 redirect entire subdirectory to a single pagePosted: 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

301 redirect entire subdirectory to a single pagePosted: 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
Administrateur - Site Admin


Joined: 28 Apr 2006
Posts: 14403

301 redirect entire subdirectory to a single pagePosted: Sun Nov 25, 2007 3:06 pm    Post subject: Re: 301 redirect entire subdirectory to a single page

What about :

Code:
RedirectPermanent /sub http://www.example.com


Before :

Code:
RewriteEngine On


If it's not enough to get rid of the _GET vars, it may be easier to deal with it in the target file directly.

++

_________________
Useful links :
SEO Forum || SEO Directory || SEO phpBB || SEO phpBB3 || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Référencement phpBB3 || Recherche
Back to top
Visit poster's website
ebnx



Joined: 01 Nov 2007
Posts: 21

301 redirect entire subdirectory to a single pagePosted: 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
Display posts from previous:   
Post new topic   Reply to topic    phpBB SEO » SEO Forum  » Apache mod Rewrite
Page 1 of 1

Navigation Similar Topics

Jump to: