Forum Moderators: phranque
I want all pages in: http://www.example.com/sub/
To be 301 redirected to: http://www.example.com/page.html
I thought I could do it by adding the following command to my .htaccess file:
Redirect 301 /sub http://www.example.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 (one page to another page) in the past.
Thanks for your help!
[edited by: jdMorgan at 3:58 pm (utc) on Nov. 24, 2007]
[edit reason] example.com [/edit]
What you need is the RedirectMatch directive, which can be told to 'drop' path information:
RedirectMatch 301 ^/sub(.*)$ http://www.example.com/page.html
Jim
As I said before, I wanted all pages in a specific subdirectory:
http://www.example.com/sub/
To redirect to a specific page:
http://www.example.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.example.com/sub/example.php?id=section1
And using your suggested .htaccess directive, they are being redirected/rewritten as
http://www.example.com/page.html?id=section
Anyone have any thoughts on how I can get rid of the "?id=section1" part?
Thanks very much!
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.htm[b]l?[/b] [R=301,L]
Options +FollowSymLinks
RewriteEngine on
Jim