Forum Moderators: phranque

Message Too Old, No Replies

.htacess prevent code from affecting subdomains

main domain rewrite is affecting subdomains

         

Kallym

7:14 pm on Feb 18, 2010 (gmt 0)

10+ Year Member



Hello, I have a hosting account where I have one main domain and several subdomains. The main domain is a Joomla site that uses SEF URLs and is an online art gallery. The subdomains are standalone web sites (not Joomla)for the various artists (some of which use domain names and some just a subdomain name).

The .htaccess file has a section in it that pertains to the SEF urls used for the main domain. It is affecting all of the sites/subdomains. So I need to insert a condition that instructs to do the following for example.com or www.example.com, but not for subdomain.example.com or otherexample.com

Would something similar to the line below work as the first line in the section below? As written it breaks the SEF urls.

RewriteCond %{HTTP_HOST} ^(www.)?\example\.com [NC]

Here is the current code:


########## 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]


I would be happy to include the entire .htaccess file if that would help.

Thank You!

jdMorgan

12:56 am on Feb 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest fixing the escaping on the new RewriteCond, deleting the redundant used-to-be-third RewriteCond, optimizing the pattern in the used-to-be-fourth RewriteCond (eliminating redundancies), and putting the file- and directory-exists checks last, so they are not run unless necessary (they are extremely slow and server resource-intensive, and should be avoided whenever possible).

This change will prevent the SEF rules from executing unless the request is for example.com or www.example.com, and make them run quite a bit faster as well.

########## Begin - Joomla! core SEF Section
#
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteCond %{REQUEST_URI} (\.php|\.html?|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

If this still 'breaks' the SEF rule, then please explain exactly what you mean by 'breaks', how you tested, what results you got, and how those differed from your expectations. Also include any relevant entries from your server error log file.

Jim

Kallym

2:42 am on Feb 19, 2010 (gmt 0)

10+ Year Member



Cool! That worked! I knew I was close, but couldn't figure out the syntax for that line. I'm still learning.

What was breaking, when I added that new rewriteCond, was the functionality of the SEF urls and I would get a 404 error. I'm assuming that was because of the errors in my line.

I also fixed that line in my "require www." section which is just above the Joomla SEF section. It was not working, either (had no effect at all). And now that I examine the changes you made I understand why. So, the require www. is now working, and I got two fixes with one answer! Thank you so much!

Corrected code for require www. on main domain section:

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

jdMorgan

5:19 am on Feb 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may find that with the modified Joomla RewriteCond order and patterns, your site will be a bit 'snappier' under heavy load as well. That kind of fix can prevent an early server upgrade in some situations.

Jim

Kallym

6:06 am on Feb 19, 2010 (gmt 0)

10+ Year Member



Optimizing that code was a great bonus! I really appreciate that. I wouldn't doubt there are other areas of my .htaccess file that could also use better optimized code. But, I will save that for another post. Thank you for everything you do!