Forum Moderators: phranque

Message Too Old, No Replies

301 redirect issue

logs are showing bots hitting 1$

         

youfoundjake

10:24 pm on Nov 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



my .htaccess has this in it...

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


The 301 is not working when going to example.com
I checked the header status, and I'm getting a 301 redirect, but the server is giving a status of 500 right after it, and when I type it manually in the address bar, I get the page cannot be displayed error.

Also looking through my logs, ask.com queried for 1$ which of course gave a 404, any ideas on what is going on?

youfoundjake

11:47 pm on Nov 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



k, i took out the module for wordpress, and now it works, will have to figure a way around that.

jdMorgan

1:42 am on Nov 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A proper way to integrate all of this would be:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
#
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# BEGIN WordPress
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

I removed the <IfModule> code to prevent a silent failure on servers that don't support mod_rewrite, re-arranged the code to put all of the 'setup' directives at the top, and corrected several errors and inefficiencies. The additional RewriteCond prevents a wasteful double-call to the filesystem manager to check for file exists and directory exists.

Jim

[edited by: jdMorgan at 1:43 am (utc) on Nov. 26, 2007]

youfoundjake

4:14 am on Nov 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks Jim. Question for you...
If I'm wanting to redirect index.php to / would RewriteRule . / [L]
be the correct way?

jdMorgan

4:32 am on Nov 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, but try a WebmasterWorld search for that.

Jim

youfoundjake

5:00 pm on Nov 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I did a search around, and came across this thread:
[webmasterworld.com...]

And wouldn't you know it, the same thing happens to me, even taking into account what g1smd wrote towards the bottom.

I did modify the example, by removing the IfModules, as well as the reference to .htm since I'm only concerned with .php for the time being..

I'll keep poking around until I get it or cause my hosting provider to have a kernel panic? Heeh.

jdMorgan

10:01 pm on Nov 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> And wouldn't you know it, the same thing happens to me, even taking into account what g1smd wrote towards the bottom.

What specifically, is the problem?

Jim

youfoundjake

10:47 pm on Nov 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When i type in example.com/index.php it 301's to www.example.com/index.php so the non-www to www is working but not the index.php to /
When I looked at the example in the link, I thought he was trying to make it go from example.com/index.php to www.example.com/ which is the same result I want, but still getting the index.php stuck on the end.

jdMorgan

10:55 pm on Nov 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make sure that all of your external redirects appear first in the code, in most-specific to least-specific order, followed by your internal redirects, again in most-specific to least-specific order. Also be sure you've got [L] flags on all rules. These steps will prevent an external redirect from 'exposing' an internal rewrite to the client.

Jim

youfoundjake

1:24 am on Nov 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




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

http://www.example.com/$1 [R=301,L]
#
# BEGIN WordPress

# END WordPress


I would imagine that would have worked.
I also had
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]

inside Wordpress, but that didn't work either.

jdMorgan

1:37 am on Nov 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Most-specific first:

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

Upload this code, then completely flush your browser cache (Temporary internet files for IE) before testing.

Jim

youfoundjake

4:10 am on Nov 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



heeh, can't believe i didn't clear the cache, sigh... so i uploaded the .htaccess file, but forgot to put my domain in, and it freaking forward to the actual www.example.com domain, but it processed all the rules on my server. neat-o