Forum Moderators: phranque

Message Too Old, No Replies

Optimizing blog software for Google

.htaccess issues

         

Shiznaught

12:56 am on Nov 13, 2006 (gmt 0)

10+ Year Member



After reading the following thread I'm trying to add 301 redirects from domain.com to www.domain.com for some of my sites:

[webmasterworld.com...]

Unfortunately it doens't work so well with an installation of a popular blog software. domain.com redirects to www.domain.com fine, but domain.com/blog-post/ redirects to www.domain.com/index.php, and www.domain.com/index.php does not redirect to www.domain.com. Here is the original .htaccess that comes with the blog software:

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

Here's the htaccess code that I'm trying to integrate with that:

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

Anyone know how this can be accomplished?

[edited by: encyclo at 2:25 am (utc) on Nov. 13, 2006]
[edit reason] examplified, see TOS [webmasterworld.com] [/edit]

jdMorgan

3:16 am on Nov 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note that "index\.html" in both lines the first redirect should probably be changed to "index\.php" for the site you described.

Then put the two redirects ahead of the blog rewrite -- That should work.

Note also that this forum deletes required space characters between "}" and "!" in code posted here.

Jim

Shiznaught

6:34 am on Nov 13, 2006 (gmt 0)

10+ Year Member



Thanks for the help, Jim. I think it was your code that I used from that thread. I made the changes you suggested, and now it seems like all is working well, except www.domain.com/index.php still doesn't redirect to www.domain.com. Here's the code:

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

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

jdMorgan

10:05 pm on Nov 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



/index.php still doesn't redirect

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.[b]php[/b]\ HTTP/
RewriteRule index\.[b]html[/b]$ http://www.domain.com/%1 [R=301,L]

From my post above:
Note that "index\.html" in both lines of the first redirect should probably be changed to "index\.php" for the site you described.

The patterns for the file extensions in both lines must match, or the rule will never be invoked:


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

Jim

Shiznaught

6:59 am on Nov 15, 2006 (gmt 0)

10+ Year Member



Thanks for the follow-up, Jim. It was pretty late at night when I made that post, and it's late right now as well, but I fixed the missed html to php, and looks like it's working properly now.