Forum Moderators: mack

Message Too Old, No Replies

Will this redirect solve my problem

www versus non-www

         

digic

12:52 pm on Oct 19, 2006 (gmt 0)

10+ Year Member



when I searched "site:www.mysite.com" I only get the index page as a result but when I searched for "site:mysite.com" I get almost every page on my website.

I have read that 301 redirect can fix this, but when I look at CPanel I only got this option

ADD REDIRECT:
[mysite.com...] >>> [mysite.com...]
PERMANENT

and it ads string on the bottom of htacess file like:
RedirectMatch permanent ^/$ [mysite.com...]

Will this solved my problems? Or are there any other more strings/script to be made when I want all the pages to be resolved as www.mysite.com?

The Contractor

1:03 pm on Oct 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



better to put this directly in your .htaccess as I don't believe what you have could work:

RewriteCond %{HTTP_HOST}!^www\.mysite\.com [NC]
RewriteRule ^(.*)$ [mysite.com...] [R=301,L]

If you cannot see your .htaccess in your FTP client - make sure you are viewing hidden files. Also, make sure to edit your .htaccess using something like TextPad, UltraEdit etc.

digic

1:49 pm on Oct 19, 2006 (gmt 0)

10+ Year Member



I can see and modify the htaccess using cuteftp on public_html. But since I am using Wordpress the htaccess has this on top:

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

# END WordPress

Will this have a conflict if I put the strings you suggested? Thanks a lot.

The Contractor

2:11 pm on Oct 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



nope, I would think not as I have played around setting up WP for others and never ran into the problem. Include the code given starting on a new line after everything currently in your .htaccess

digic

5:31 am on Oct 20, 2006 (gmt 0)

10+ Year Member



So my htaccess files content would be like this:

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

RewriteCond %{HTTP_HOST}!^www\.mysite\.com [NC]
RewriteRule ^(.*)$ [mysite.com...] [R=301,L]
==================================================

Just to make sure before I implement it. Thanks a lot for your help.

The Contractor

11:39 am on Oct 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



correct

digic

11:43 am on Oct 20, 2006 (gmt 0)

10+ Year Member



The Contractor, Thanks a lot for your help. I have implemented it. I'll just wait for the results.

jdMorgan

1:09 pm on Oct 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are some required spaces missing, and the rule order needs to be fixed:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
#
# Redirect to canonical domain
RewriteCond %{HTTP_HOST} !^www\.mysite\.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
#
# BEGIN WordPress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>

Jim

digic

10:24 am on Oct 21, 2006 (gmt 0)

10+ Year Member



thanks, noted and updated

digic

2:00 pm on Oct 30, 2006 (gmt 0)

10+ Year Member



Hi,

What if its is a subdirectory such as

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

# END WordPress

==Would it be like:====

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /subdirectory1/
#
# Redirect to canonical domain
RewriteCond %{HTTP_HOST}!^www\.mysite\.com [NC]
RewriteRule (.*) [mysite.com...] [R=301,L]
#
# BEGIN WordPress
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /subdirectory1/index.php[L]
# END WordPress
</IfModule>