Forum Moderators: phranque
I'm trying to make sure that any url accessed without ["WWW"...] is rewritten or redirected to the same request WITH the WWW.
mydomain.com = www.mydomain.com
or
mydomain.com/users/login.php =
www.mydomain.com/users/login.php
I've used about 5-6 blocks of code and here is my experience:
I'm able to get the root redirected properly: domain.com to www.domain.com but anything else such as domain.com/users/ will redirect to www.domain.com as well.
I've also used rewrites that has FF tell me it will redirect forever. A potential issue with cookies (Which its not).
I think my problem is that I've installed Joomla and there is already code for Search Engine Friendly URLs. Here it is.
RewriteEngine On
########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/¦\.php¦\.html¦\.htm¦\.feed¦\.pdf¦\.raw¦/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section
Can anyone help me find a way to make sure that my top level and all trailing levels will go to the "WWW." version of themselves?
Didn't know I needed to, I more just need the strings I'm missing to make it work but sure, here are the three blocks I tried.
redirectMatch 301 ^(.*)$ [domain.com...]
redirectMatch permanent ^(.*)$ [domain.com...]
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ [domain.com...] [r=301,nc]
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) [newdomain.com...] [R=301,L]
Thanks for lookin at it
Knowing me I didn't explain myself properly, thanks!
Always list redirects before rewrites. If you don't, you'll start exposing internal filepaths back out into URLs, and you don't want that.
Stick to the exact capitalisation used in the Apache manual for RewriteRule, HTTP_HOST, and so on, for the best possible chance of future compatibility.
Note that
^(.*)$ can be simplified to (.*) here.
Options +FollowSymlinks
RewriteEngine on
#
# Externally redirect to canonicalize hostname unless exact match on canonical domain
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# Begin - Joomla! core SEF Section
#
# If requested URL does not resolve to existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# And requested URL-path is not already index.php
RewriteCond %{REQUEST_URI} !^/index.php
# And requested URL-path resolves to a specific filetype or has no filename or filetype
RewriteCond %{REQUEST_URI} (\.php¦\.html?¦\.feed¦\.pdf¦\.raw¦/[^.]*)$ [NC]
# Then internally rewrite to Joomla index.php
RewriteRule (.*) index.php
#
# Unconditionally set HTTP_AUTHORIZATION variable and invoke
# the preceding index.php rewrite (if applicable)
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
# End - Joomla! core SEF Section
Replace all broken pipe "¦" characters with solid pipes before use; Posting on this forum modifies the pipe characters.