Redirection to www. using htaccess

General questions relating to Joomla! 1.5 There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
User avatar
jaman_vvip
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Fri Aug 29, 2014 2:13 pm
Location: Bangladesh
Contact:

Re: Redirection to www. using htaccess

Post by jaman_vvip » Wed Dec 03, 2014 4:53 pm

g1smd wrote:Some of the errors.

This code does not redirect host requests with appended port name, and therefore allows Duplicate Content.

Code: Select all

RewriteCond %{HTTP_HOST} ^yoursite\.com$ [NC]
RewriteRule .* http://www.yoursite.com/ [L,R=301]
Consider what happens if example.com/index.php is requested in the next code. The first ruleset redirects to http://www.example.com/index.php and the second ruleset creates a second redirect to http://www.example.com/. You should avoid creating a redirection chain.

Code: Select all

RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule index\.php$ http://www.yoursite.com/%1 [R=301,L]
The code also does not redirect index URLs within folders. It can only do the root.

The "referrer" code is horrible, likely able to be replaced with a single line of code. There are multiple errors in it, not least the lack of escaping on literal periods. Additionally, code like that should go ahead of all the other stuff. Why redirect some requests and then block them. Why not do the blocking first?

There are replacement default .htaccess files for Joomla 1.5 http://joomlacode.org/gf/project/joomla ... m_id=25090 and Joomla 1.6 http://joomlacode.org/gf/project/joomla ... m_id=22425 awaiting commit. The new files fix a number of problems.

User avatar
jaman_vvip
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Fri Aug 29, 2014 2:13 pm
Location: Bangladesh
Contact:

Re: Redirection to www. using htaccess

Post by jaman_vvip » Wed Dec 03, 2014 4:54 pm

This process works for me


Locked

Return to “General Questions/New to Joomla! 1.5”