Forum Moderators: phranque

Message Too Old, No Replies

rules only for root domain and not for subdomain

how to make root domain htaccess to not affect subdomain

         

zaldun

6:23 pm on Oct 23, 2006 (gmt 0)

10+ Year Member



Hi all.

I am developing a website in PHP + MySQL, which makes 'heavy' use of URL rewriting, for example:

================
Options +FollowSymLinks
RewriteEngine On

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

RewriteRule login/?$ login.php [NC,L]
RewriteRule register/([a-z0-9]+)/?$ register.php?rc=$1 [NC,L]
RewriteRule request/?$ request.php [NC,L]
RewriteRule ([a-z0-9\_-]+)/logout/?$ logout.php?account=$1 [NC,L]
(and other 20 or more rules ...)
=================

the problem is that i defined a subdomain like blog.mydomain.net, where i installed Wordpress, and i wouldnt want the .htaccess have effect into the subdomain, when i insert the URL: http:://blog.mydomain.net
as when i load that URL i get:

==================
Not Found
The requested URL /home/mydomain/public_html/index.php was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/1.3.37 Server at blog.mydomain.net Port 80
=================

take in count that the subdomain absolute path is : /home/mydomain/public_html/blog

if i try adding some rule to make a simple redirect i fall into infinite loop, like:

RewriteCond %{HTTP_HOST} ^blog.mydomain.net$ [NC]
RewriteRule ^(.*)$ http:://blog.mydomain.net/$1 [R=301,L]

The idea is that any rule working for the domain shouldnt have any effect at the subdomain; say also that if loading the index page of blog, like: http:://blog.mydomain.net/index.php then it works, and other pages too, but if i load profile.php in wp-admin subfolder of the subdomain then it doesnt work ...
maybe need a directive for subdomain to search for index.htm index.html index.php default.htm etc?

I guess i am missing something here (related to rules in the .htaccess of root domain), so i would appreciate some light about this issue, thanks in advance.

Ibon

[edited by: jdMorgan at 6:37 pm (utc) on Oct. 23, 2006]
[edit reason] De-linked [/edit]

jdMorgan

6:35 pm on Oct 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just tell mod_rewrite to exit before processing your other rewrites by adding this code above those other rules:

RewriteCond %{HTTP_HOST} ^blog\.mydomain\.net(:80)?$ [NC]
RewriteRule (.*) - [L]

That will disable any rewriterules that follow it if the requested hostname is blog.mydomain.net.

If you need finer control, see the RewriteRule [S] (skip) flag, or add a negative RewriteCond to each rule you don't want processed for the blog subdomain. Example:


RewriteCond %{HTTP_HOST} !^blog\.mydomain\.net$ [NC]
RewriteRule login/?$ login.php [NC,L]

Jim

zaldun

6:59 pm on Oct 23, 2006 (gmt 0)

10+ Year Member



I guess i started to think in odd, or complex ways to solve the problem, when it is always to choose the most simple way, in this case just tell to mod-rewrite to do (rewrite) nothing!

RewriteRule (.*) - [L]

thanks a lot for the help!