PDA

View Full Version : 301 redirect to www


spin
12-02-2008, 07:06 AM
HI all

Having problems with a 301 redirect. I have edit my .htaccess file several ways, all without success. This is what is in my file now

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

# END WordPress

<Files 403.shtml>
order allow,deny
allow from all
</Files>

deny from 208.117.236.74
deny from 96.6.147.191
deny from 96.7.67.191

This is what I have been adding to the above file

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

I have add the above with domain changed to mine of course at top and bottom. Nothing has worked...basically I get an error stating a redirect is trying to perform in a way that wont work...lol...that seems to be my style since I started this project...lol...Thanks in advance :D

Opps I meant 301 redirect

Kevin
12-02-2008, 01:09 PM
Hey Spin

It sounds like you are trying to make the url of your blog go to www all the time. You don't actually need to edit the htaccess yourself to achieve this as wordpress does this for you. Make sure wordpress can modify the htaccess file and then set the url of your blog via the settings area (to either site.com or www.site.com).

If you try and add a 301 redirect on top of the code wordpress adds it will conflict and mess things up.

Donace
12-02-2008, 01:20 PM
as kevin has said it look like you have set your wordpress installation to direct to non www. so it just creates a loop.

Can't remember exactly where in wordpress the setting is..but check settings (thinks in general)...remove the bit from the htaccess that you added and let wordpress do it for you.

Kevin
12-02-2008, 01:22 PM
as kevin has said it look like you have set your wordpress installation to direct to non www. so it just creates a loop.

Can't remember exactly where in wordpress the setting is..but check settings (thinks in general)...remove the bit from the htaccess that you added and let wordpress do it for you.

when you click on the settings tab its the first page (ie. General) :)

navjotjsingh
12-02-2008, 01:29 PM
AFAIK...Wordpress won't help if you type the non www url keeping the www url in wordpress setting page. Homepage will still open with the non www url. Wordpress only ads the permalinks setting in the .httaccess file. Only thing wordpress helps is in keeping the page links and other internal links with the www when they are displayed. But without www links will still be accessible unless you make manual changes.

ap4a
12-02-2008, 02:27 PM
Edit: never mind, my method's out of date :)

By the way, you might want to update the topic title from 302 to 301 to prevent confusion.

spin
12-02-2008, 04:19 PM
Hey Spin

It sounds like you are trying to make the url of your blog go to www all the time. You don't actually need to edit the htaccess yourself to achieve this as wordpress does this for you. Make sure wordpress can modify the htaccess file and then set the url of your blog via the settings area (to either site.com or www.site.com).

If you try and add a 301 redirect on top of the code wordpress adds it will conflict and mess things up.

Wow simply solution. LOL thanks and thanks to every one else for helping.

sarahG
12-03-2008, 09:59 AM
To be honest, I would still recommend a 301 redirect.

The top of my htaccess file includes the WP permalinks code and then ensures the correct domain version is displayed ie. the www version

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

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

# END WordPress

RewriteCond %{HTTP_HOST} !^www\.stuffbysarah\.net
RewriteRule (.*) http://www.stuffbysarah.net/$1 [R=301,L]

The last two lines here simply say

If the HTTP HOST (ie. the domain less the http://) is not what I want it to be ie. www.stuffbysarah.net, then do a 301 redirect to www.stuffbysarah.net and append any additional requested URI onto the end ie. http://stuffbysarah.net/category/business/ would forward to http://www.stuffbysarah.net/category/business/

Whilst WordPress does insert the correct http host within the permalinks, I wouldn't rely on it. The htaccess method is a reliable solution.