Forum Moderators: phranque

Message Too Old, No Replies

301 redirect help

         

flyingcat

7:30 am on Oct 9, 2005 (gmt 0)

10+ Year Member



How to redirect "http://www.example.com/forums/index.php" to "http://www.example.com/forums/" using 301?

I've tried this:
rewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
rewriteRule ^index\.php$ http://www.example.com/forums/ [R=301,L]

But didn't work.

Thanks!

[edited by: jdMorgan at 3:15 am (utc) on Oct. 10, 2005]
[edit reason] Example.com [/edit]

jd01

8:43 am on Oct 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi flyingcat,

Welcome to WebmasterWorld.

It appears you were *very* close... My guess is this is in your root .htaccess, in which case, you will need to use the full path to the file:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /forums/index\.php\ HTTP/
RewriteRule ^forums/index\.php$ http://www.example.com/forums/ [R=301,L]

Hope this helps.

Justin

[edited by: jdMorgan at 3:16 am (utc) on Oct. 10, 2005]
[edit reason] Example.com [/edit]

flyingcat

2:06 pm on Oct 9, 2005 (gmt 0)

10+ Year Member



Thanks for your reply.
I added above to .htaccess in root directory. But didn't work. When reloaded http://www.example.com/forums/index.php, no action.

[edited by: jdMorgan at 3:16 am (utc) on Oct. 10, 2005]
[edit reason] Example.com [/edit]

jd01

5:09 pm on Oct 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have any other rules? If not you will need RewriteEngine on, and may need to set the options.

Like this:
#Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /forums/index\.php\ HTTP/
RewriteRule ^forums/index\.php$ http://www.example.com/forums/ [R=301,L]

Test this with the Options commented out, then if it does not work, uncomment by removing the #.

If you still get no response, try a test page to make sure mod_rewrite is enabled and you have permission to use it:

#Options +FollowSymLinks
RewriteEngine on
RewriteRule ^test\.html$ http://www.example.com/ [R=301,L]

Type test.html in to your browser and if you are redirected to your home page, then mod_rewrite is on and working, so there must be something we are missing. If not, you probably need to change hosts to use it -- most either allow you to use it or do not.

Let us know how it goes.

Justin

Added: BTW is this in the .htaccess or the httpd.conf file? If it is in the conf file, you will need to change the left side path to start with a / EG RewriteRule ^/forums/index\.php$

[edited by: jdMorgan at 3:16 am (utc) on Oct. 10, 2005]
[edit reason] Example.com [/edit]

flyingcat

9:17 pm on Oct 9, 2005 (gmt 0)

10+ Year Member



Hi, jd01
Your code is correct. I've found the problem that I also have a .htaccess file in my /forums/ directory, which caused the problem. When I deleted it, the code below works well.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /forums/index\.php\ HTTP/
RewriteRule ^forums/index\.php$ http://www.example.com/forums/ [R=301,L]

In addition, I find there are other URLs generated by my forum point to the forum index page.

http://www.example.com/forums/index.php?
http://www.example.com/forums/index.php?act=idx

How to rewrite these two URLs?

Thanks!

[edited by: jdMorgan at 3:18 am (utc) on Oct. 10, 2005]
[edit reason] Example.com [/edit]

jd01

4:32 pm on Oct 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will need to either add to the cond. or remove the ending, personally, I prefer to remove the ending, unless I need to use a pattern, so I have a back-reference, or I need to NOT redirect some pages.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /forums/index\.php

OR

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /forums/index\.php\?variable=.*\ HTTP/

Justin

jd01

5:08 pm on Oct 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oops!

There is an error in this line:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /forums/index\.php\?variable=.*\ HTTP/

The correction is to make the query_string optional:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /forums/index\.php(\?variable=.*)?\ HTTP/

Justin