Moving Rewrites from .htaccess to httpd.conf

Using a single web hosting account to host multiple sites

Moving Rewrites from .htaccess to httpd.conf

Postby StephenJ » Fri Aug 17, 2007 6:50 am

I am trying to move the rewrites below from an .htaccess file to httpd.conf and I am running into a problem with the rewrites not workin at all. When I place these in the .conf it is as if they don't fire..


===================================

Options +FollowSymLinks

RewriteEngine On

# .com, .net, .org, etc. catch all for adding www.

RewriteCond %{HTTP_HOST} ^([^\.]+\.(com|org|eu|com\.au|net|cc|nl|info|us|biz|co.\uk))$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,QSA,L]

# SUB DOMAIN REWRITES

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^(www\.mydomain1\.com)?$ [NC]
RewriteCond %{HTTP_HOST} !^(www\.mydomain2\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.guildlaunch\.com/?$ [NC]
RewriteRule ^(.*)$ /guild/$1?sub_domain=%1 [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.mydomain1\.com)?$ [NC]
RewriteCond %{HTTP_HOST} !^(www\.mydomain2\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.guildlaunch\.com$ [NC]
RewriteRule ^index.php$ /guild/index.php?sub_domain=%1 [QSA,L]

# FULL DOMAIN REWRITES

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^(www\.mydomain1\.com)?$ [NC]
RewriteCond %{HTTP_HOST} !^(www\.mydomain2\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.([^\.]+\.(com|org|eu|com\.au|net|cc|info|us|biz|nl|co.\uk))$ [NC]
RewriteRule ^(.*)$ /guild/$1?full_domain=%2&mrw=1 [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.mydomain1\.com)?$ [NC]
RewriteCond %{HTTP_HOST} !^(www\.mydomain2\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.([^\.]+\.(com|org|eu|com\.au|net|cc|info|us|biz|nl|co.\uk))$ [NC]
RewriteRule ^index.php$ /guild/index.php?full_domain=%2&mrw=2 [QSA,L]

===============================

Can anyone tell me why the redirects aren't running in the .conf file? I appreciate the input.

-Stephen
StephenJ
 
Posts: 3
Joined: Mon Nov 20, 2006 2:37 pm

Postby richardk » Fri Aug 17, 2007 2:41 pm

Where are you putting it in the httpd.conf file? Between <Directory> or <VirtualHost>, or just in it (between nothing)?

It shouldn't completely fail, in a <VirtualHost> or between nothing it needs a / at the start of RewriteRule patterns, try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# .com, .net, .org, etc. catch all for adding www.
RewriteCond %{HTTP_HOST} ^([^\.]+\.(com|org|eu|com\.au|net|cc|nl|info|us|biz|co\.uk))$ [NC]
RewriteRule ^(/.*)$ http://www.%1$1 [R=301,QSA,L]

# SUB DOMAIN REWRITES
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^(www\.guildlaunch\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.guildlaunch\.com$ [NC]
RewriteRule ^(/.*)$ /guild$1?sub_domain=%1 [QSA,L]

RewriteCond %{HTTP_HOST} !^(www\.guildlaunch\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.guildlaunch\.com$ [NC]
RewriteRule ^index\.php$ /guild/index.php?sub_domain=%1 [QSA,L]

# FULL DOMAIN REWRITES
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^(www\.mydomain1\.com|www\.mydomain2\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.([^\.]+\.(com|org|eu|com\.au|net|cc|info|us|biz|nl|co\.uk))$ [NC]
RewriteRule ^(/.*)$ /guild$1?full_domain=%2&mrw=1 [QSA,L]

RewriteCond %{HTTP_HOST} !^(www\.mydomain1\.com|www\.mydomain2\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.([^\.]+\.(com|org|eu|com\.au|net|cc|info|us|biz|nl|co\.uk))$ [NC]
RewriteRule ^index\.php$ /guild/index.php?full_domain=%2&mrw=2 [QSA,L]

You may need to add the REDIRECT_STATUS lines.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby StephenJ » Thu Sep 20, 2007 3:01 am

Ok. I finally got around to trying this. The server is a live server and it's working so I finally found some time to rock the boat. I placed it inside a directory block, And it does nothing:

<Directory "P:/oursite/sitedir">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.0/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All

RewriteEngine On

# .com, .net, .org, etc. catch all for adding www.

RewriteCond %{HTTP_HOST} ^([^\.]+\.(com|org|eu|com\.au|net|cc|nl|info|us|biz|co.\uk))$ [NC]
RewriteRule ^(/.*)$ http://www.%1/$1 [R=301,QSA,L]

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
Deny from XXX.XXX.XXX.XXX

AddHandler fcgid-script .php
Options +execCGI
FCGIWrapper "R:/PHP/php-cgi.exe" .php
</Directory>


I simplified my current rewrite and tried moving just the rewrite for adding the "www" to the domains and it didn't do anything. Oddly also, the rewrites that still existed in the HTACCESS didn't fire. It's almost as if this directory entry in the conf file isn't being applied. I'm on Windows BTW.

-Stephen
StephenJ
 
Posts: 3
Joined: Mon Nov 20, 2006 2:37 pm

Postby richardk » Thu Sep 20, 2007 1:19 pm

<Directories> (mostly) work the same as .htaccess files. Try your original mod_rewrite and/or replace ^(/.*)$ with ^(.*)$.

Oddly also, the rewrites that still existed in the HTACCESS didn't fire.

Does it work when you just remove the mod_rewrite in the <Directory>? did you change anything else?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 52 guests

cron