tags:

views:

52

answers:

3

Hey all,

Can someone please help me to force my website to redirect to using www. and ALWAYS add a slash at the end of any page? My htaccess file currently looks like this:

RewriteEngine on

RewriteRule blog/date/([^/]+)/?$ index.php?page=viewblog&date=$1
RewriteRule blog/([^/]+)/?$ index.php?page=viewblog&category=$1
RewriteRule blog/([^/]+)/([^/]+)/?$ index.php?page=viewblog&category=$1&title=$2

RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([a-zA-Z0-9]+)

Many thanks in advance :)

A: 

I do not know how to add the trailing slash, but adding www in front of URLs are quite simple. Here's what im using to add the www before an url:

RewriteEngine on

Options FollowSymlinks

rewritecond %{http_host} ^yourdomain.com [nc]

rewriterule ^(.*)$ http://www.yourdomain.com/$1 [r=301,nc]

Googled for the trailing slash-thingy and found this article: http://www.mydigitallife.info/2007/03/19/add-trailing-slash-to-the-end-of-the-url-with-htaccess-rewrite-rules/

Hope this helps :-)

Burbas
A: 

Just do this:

RewriteRule ^(.*) http://www.YOURDOMAIN.com/$1/ [R=301,L]

Regards,
Dennis M.

RageD
Thanks for your answer - Only problem with this is that it adds a slash to the main domain as well, so it has "http://www.yourdomain.com//"
Tim
+1  A: 

This will work for any domain:

DirectorySlash on
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [L]

This will add the slash when necessary. (%{REQUEST_URI} will be / with a request for root, or /whatever if you request domain.com/whatever.) It also won't put in two slashes (//) for the main domain as the other solution does. The DirectorySlash directive ensures the slash is added where appropriate even if the www is already present.

qmega