Forum Moderators: phranque

Message Too Old, No Replies

Whats wrong with my 301 redirect?

htaccess file codes...

         

financialhost

12:53 am on Jan 29, 2006 (gmt 0)

10+ Year Member



Can anyone help me with doing a 301? I am not very good at this...

I want to redirect the following with a 301
[widgets.com...] to [widgets.com...]
[widgets.com...] to [widgets.com...]
[widgets.com.index.htm...] to [widgets.com...]
[widgets.com...] to [widgets.com...]

I got as far as this before giving up,

RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.widgets\.com
RewriteRule (.*) [widgets.com...] [R=301,L]
rewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+/)?index\.php\ http
rewriteRule ^(.+/)?index\.php$ [widgets.com...] [R=301,L]

Any help appreciated

mikeruss

6:09 pm on Jan 29, 2006 (gmt 0)

10+ Year Member



You may get the solution here?

<snip>

[edited by: jdMorgan at 9:10 pm (utc) on Jan. 29, 2006]
[edit reason] No URLS, please. See TOS. [/edit]

jdMorgan

9:08 pm on Jan 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest:

RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^([^/]+/)*index\.php$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

I rearranged your two rules, then expanded the second of your rules into two rules, one to cover the root index file, and a second one to cover subdirectories. This was the simplest way I found to avoid a missing trailing slash on the root index file request.

Take care with upper/lowercase usage on Apache and *nix -- A major problem with your code was that 'http' would never match any client request, thus disabling that rule.

Jim

financialhost

12:31 am on Feb 4, 2006 (gmt 0)

10+ Year Member



I could not actually get this to work...

First of all the main thing i need to do is redirect [site.com...] to
[site.com...]

I placed the htaccess file in the forums directory & was able to make index.php redirect but not index.php?

My code if below,

RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php?\ HTTP/
RewriteRule ^index\.php?$ [site.com...] [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php?\ HTTP/
RewriteRule ^([^/]+/)*index\.php?$ [site.com...] [R=301,L]

Any help really appreciated because i have a serious duplication URL issue that has blasted my forums out of the index... + i am not able to find all the ways in vbulletin to stop it linking to index.php?

Thanks...

jdMorgan

1:45 am on Feb 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Question marks have special meaning in regular expressions patterns -- they are not interpreted as literal question marks unless you precede them with "\". However, the "?" is never 'seen' by rewriterule as a literal under any circumstances, since it demarcates a query string, and RewriteRule does not handle query strings (You must use RewriteCond to handle query strings).

The following should work better:


RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.p[b]hp[^\ ]*\[/b] HTTP/
RewriteRule ^index\.p[b]hp$[/b] http://www.example.com/foru[b]ms/[/b] [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.p[b]hp[^\ ]*\[/b] HTTP/
RewriteRule ^([^/]+/)*index\.p[b]hp$[/b] http://www.example.com/foru[b]ms/[/b]$1 [R=301,L]

> i have a serious duplication URL issue that has blasted my forums out of the index

That's one of the main reasons we get so many of these threads... ;)

For more information on mod_rewrite and regular expressions, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

financialhost

3:08 pm on Feb 4, 2006 (gmt 0)

10+ Year Member



The last code almost works...

www.site.com/forums/index.php to www.site.com/forums/ works.

www.site.com/forums/index.php? to www.site.com/forums/ does not work...

Instead it redirects to www.site.com/forums/?

With the? on the redirection destination.

Any more ideas?

Sorry to be a pain but i am not technical enough to work this out & currently i have lost all traffic to my forums...

I must get rid of this duplication.

Any help appreciated

rmiranda

4:16 pm on Feb 4, 2006 (gmt 0)

10+ Year Member



financialhost,

Do the directives

RewriteEngine on
#
RewriteCond %{HTTP_HOST}!^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

worked to you?

They do not for me. I`m following up your discussion. May you or somebody else help me?

My sites are hosted in a Unix virtual server, on an unique IP and different domains names of my own. I also use Webmin. The help sent by the support of my server didn`t worthy.

The Apache directives in /usr/local/apache/htdocs/imanager/.htaccess are:

Options FollowSymLinks ExecCGI
AddType application/x-httpd-cgi .cgi
DirectoryIndex index.cgi

<Limit GET POST>
allow from all
</Limit>

And I used the directives from your firts message on root of each site.

In addition, I`d like to solve the problem to all sites on the server, instead site after site. Is there a solution? The directives for the IP address are:

SSLDisable
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteOptions inherit
</IfModule>

On the end, I`m interested also to follow up your discussion about forum.php because I`ll begin to run my forum on the next days.

Thanks in advance,
rmiranda

rmiranda

11:45 pm on Feb 4, 2006 (gmt 0)

10+ Year Member



Sorry by the grammar errors. On the end I wanted to type forums/index.php not forum.php

rmiranda

jdMorgan

11:45 pm on Feb 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Append a question mark to the substitution URLs to clear the query string and remove the original question mark. The question marks added at the end will not be present in the actual new URLs.

RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php[^\ ]*\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/forum[b]s/?[/b] [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php[^\ ]*\ HTTP/
RewriteRule ^([^/]+/)*index\.php$ http://www.example.com/forums/[b]$1?[/b] [R=301,L]

Jim