You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "--[ UxBoD ]--" <ux...@splatnix.net> on 2011/01/20 21:00:33 UTC

[users@httpd] mod_rewrite woes

Hello all,

I am switching from LiteSpeed webserver to Apache and having a real issue with mod_rewrite.  First of all here are the details of apache:

Server version: Apache/2.2.17 (Unix)
Server built:   Jan 20 2011 16:15:22
Server's Module Magic Number: 20051115:25
Server loaded:  APR 1.4.2, APR-Util 1.3.10
Compiled using: APR 1.4.2, APR-Util 1.3.10
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/usr/local/apache"
 -D SUEXEC_BIN="/usr/local/apache/bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

I have included the necessary module:

LoadModule rewrite_module     modules/mod_rewrite.so

and have tested that it works by touching a file called test.html and making it redirect to another site using the following .htaccess rule:

Redirect /test/test.html http://httpd.apache.org

Now the issue comes when I am trying to redirect a domain URL in the following formats:

http://somedomain.com
http://somedomain.co.uk
http://www.somedomain.co.uk

and wish them all to be re-written as:

http://www.somedomain.com

I have tried using the following rule:

RewriteCond %{HTTP_HOST} ^somedomain.co.uk$ [NC,OR]
RewriteCond %{HTTP_HOST} ^somedomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.somedomain.co.uk$ [NC,OR]
RewriteRule ^(.*)$ http://www.somedomain.com/$1 [R=301,L]

But it always ends up just showing the domain I entered and not re-directing :(

Am I doing something really stupidly crazy as I do not have much more hair to pull out :) Looking for some kind assistance.
-- 
Thanks, Phil

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by "--[ UxBoD ]--" <ux...@splatnix.net>.
----- Original Message -----
> you have rules in htaccess subverting your rules in httpd.conf.

Hmm, in httpd.conf I have the following directives for the root directory:

#
<Directory />
    Options None
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/www">
    Options -Indexes -FollowSymLinks -Includes -MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
    <LimitExcept GET POST>
        deny from all
    </LimitExcept>
</Directory>

Do they flow down to the virtuals underneath then ? I used http://security-24-7.com/hardening-guide-for-apache-2-2-15-on-redhat-5-4-64bit-edition/ to help lock down the server.

Very sorry for my lack of knowledge.
-- 
Thanks, Phil

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by Eric Covener <co...@gmail.com>.
you have rules in htaccess subverting your rules in httpd.conf.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by "--[ UxBoD ]--" <ux...@splatnix.net>.
----- Original Message -----
> What RewriteLogLevel is that? Try 9.
> 
> On Thu, Jan 20, 2011 at 3:23 PM, --[ UxBoD ]-- <ux...@splatnix.net>
> wrote:
> > ----- Original Message -----
> >> On Thu, Jan 20, 2011 at 3:10 PM, --[ UxBoD ]-- <ux...@splatnix.net>
> >> wrote:
> >> > ----- Original Message -----
> >> >> Did you set RewriteEngine on?
> >> >>
> >> >> Where do you define your rules? If there's a VirtualHost
> >> >> handling
> >> >> the
> >> >> request, they need to be defined there.
> >> >
> >> > Hello Eric,
> >> >
> >> > Thank you for the response. Yes it is a virtual host and I am
> >> > using
> >> > the following directives for it:
> >> >
> >> > <VirtualHost *:80>
> >> >    ServerAdmin webmaster@somedomain.com
> >> >    DocumentRoot "/www/somedomain.com"
> >> >    <Directory /www/somedomain.com>
> >> >        AllowOverride All
> >> >    </Directory>
> >> >    ServerName www.somedomain.com
> >> >    ServerAlias somedomain.com www.somedomain.co.uk
> >> >    somedomain.co.uk
> >> >    ErrorLog "logs/www.somedomain.com-error.log"
> >> >    CustomLog "logs/www.somedomain.com-access.log" common
> >> > </VirtualHost>
> >> >
> >> > I have hardened Apache though I did try changing the directives
> >> > in
> >> > httpd.conf for /www to have AllowOveride All as-well but to
> >> > no-avail. It seems odd though that a normal re-direct is working
> >> > fine.
> >>
<snip>
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (3) [perdir /www/somedomain.com/] strip per-dir prefix: /www/somedomain.com/ ->
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (3) [perdir /www/somedomain.com/] applying pattern '^(.*)$' to uri ''
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (4) [perdir /www/somedomain.com/] RewriteCond: input='' pattern='mosConfig_[a-zA-Z_]{1,21}(=|\%3D)' => not-matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (4) [perdir /www/somedomain.com/] RewriteCond: input='' pattern='base64_encode.*\(.*\)' => not-matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (4) [perdir /www/somedomain.com/] RewriteCond: input='' pattern='(\<|%3C).*script.*(\>|%3E)' [NC] => not-matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (4) [perdir /www/somedomain.com/] RewriteCond: input='' pattern='GLOBALS(=|\[|\%[0-9A-Z]{0,2})' => not-matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (4) [perdir /www/somedomain.com/] RewriteCond: input='' pattern='_REQUEST(=|\[|\%[0-9A-Z]{0,2})' => not-matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (3) [perdir /www/somedomain.com/] strip per-dir prefix: /www/somedomain.com/ ->
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (3) [perdir /www/somedomain.com/] applying pattern '(.*)' to uri ''
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (4) [perdir /www/somedomain.com/] RewriteCond: input='/www/somedomain.com/' pattern='!-f' => matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (4) [perdir /www/somedomain.com/] RewriteCond: input='/www/somedomain.com/' pattern='!-d' => not-matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (3) [perdir /www/somedomain.com/] strip per-dir prefix: /www/somedomain.com/ ->
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (3) [perdir /www/somedomain.com/] applying pattern '.*' to uri ''
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (5) setting env variable 'HTTP_AUTHORIZATION' to ''
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b927780/initial] (1) [perdir /www/somedomain.com/] pass through /www/somedomain.com/
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (3) [perdir /www/somedomain.com/] strip per-dir prefix: /www/somedomain.com/index.html -> index.html
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (3) [perdir /www/somedomain.com/] applying pattern '^(.*)$' to uri 'index.html'
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (4) [perdir /www/somedomain.com/] RewriteCond: input='' pattern='mosConfig_[a-zA-Z_]{1,21}(=|\%3D)' => not-matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (4) [perdir /www/somedomain.com/] RewriteCond: input='' pattern='base64_encode.*\(.*\)' => not-matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (4) [perdir /www/somedomain.com/] RewriteCond: input='' pattern='(\<|%3C).*script.*(\>|%3E)' [NC] => not-matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (4) [perdir /www/somedomain.com/] RewriteCond: input='' pattern='GLOBALS(=|\[|\%[0-9A-Z]{0,2})' => not-matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (4) [perdir /www/somedomain.com/] RewriteCond: input='' pattern='_REQUEST(=|\[|\%[0-9A-Z]{0,2})' => not-matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (3) [perdir /www/somedomain.com/] strip per-dir prefix: /www/somedomain.com/index.html -> index.html
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (3) [perdir /www/somedomain.com/] applying pattern '(.*)' to uri 'index.html'
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (4) [perdir /www/somedomain.com/] RewriteCond: input='/www/somedomain.com/index.html' pattern='!-f' => matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (4) [perdir /www/somedomain.com/] RewriteCond: input='/www/somedomain.com/index.html' pattern='!-d' => matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (4) [perdir /www/somedomain.com/] RewriteCond: input='/index.html' pattern='!^/index.php' => matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (4) [perdir /www/somedomain.com/] RewriteCond: input='/index.html' pattern='(/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$' [NC] => matched
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (2) [perdir /www/somedomain.com/] rewrite 'index.html' -> 'index.php'
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (3) [perdir /www/somedomain.com/] add per-dir prefix: index.php -> /www/somedomain.com/index.php
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (3) [perdir /www/somedomain.com/] strip per-dir prefix: /www/somedomain.com/index.php -> index.php
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (3) [perdir /www/somedomain.com/] applying pattern '.*' to uri 'index.php'
123.123.123.123 - - [20/Jan/2011:20:35:40 +0000] [www.somedomain.co.uk/sid#76adb38][rid#b969900/subreq] (5) setting env variable 'HTTP_AUTHORIZATION' to ''

-- 
Thanks, Phil

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by Eric Covener <co...@gmail.com>.
What RewriteLogLevel is that?  Try 9.

On Thu, Jan 20, 2011 at 3:23 PM, --[ UxBoD ]-- <ux...@splatnix.net> wrote:
> ----- Original Message -----
>> On Thu, Jan 20, 2011 at 3:10 PM, --[ UxBoD ]-- <ux...@splatnix.net>
>> wrote:
>> > ----- Original Message -----
>> >> Did you set RewriteEngine on?
>> >>
>> >> Where do you define your rules? If there's a VirtualHost handling
>> >> the
>> >> request, they need to be defined there.
>> >
>> > Hello Eric,
>> >
>> > Thank you for the response. Yes it is a virtual host and I am using
>> > the following directives for it:
>> >
>> > <VirtualHost *:80>
>> >    ServerAdmin webmaster@somedomain.com
>> >    DocumentRoot "/www/somedomain.com"
>> >    <Directory /www/somedomain.com>
>> >        AllowOverride All
>> >    </Directory>
>> >    ServerName www.somedomain.com
>> >    ServerAlias somedomain.com www.somedomain.co.uk somedomain.co.uk
>> >    ErrorLog "logs/www.somedomain.com-error.log"
>> >    CustomLog "logs/www.somedomain.com-access.log" common
>> > </VirtualHost>
>> >
>> > I have hardened Apache though I did try changing the directives in
>> > httpd.conf for /www to have AllowOveride All as-well but to
>> > no-avail. It seems odd though that a normal re-direct is working
>> > fine.
>>
>> Use the RewriteLog to debug.
>>
>
> Any ideas Eric please ?
>
> 123.123.123.123 - - [20/Jan/2011:20:22:05 +0000] [www.somedomain.co.uk/sid#8893968][rid#b8b1640/initial] (1) [perdir /www/somedomain.com/] pass through /www/somedomain.com/
> 123.123.123.123 - - [20/Jan/2011:20:22:05 +0000] [www.somedomain.co.uk/sid#8893968][rid#b8f3e10/subreq] (1) [perdir /www/somedomain.com/] internal redirect with /index.php [INTERNAL REDIRECT]
> 123.123.123.123 - - [20/Jan/2011:20:22:05 +0000] [www.somedomain.co.uk/sid#8893968][rid#b8f5e20/subreq] (1) [perdir /www/somedomain.com/] pass through /www/somedomain.com/index.php
>
> --
> Thanks, Phil
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>



-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by "--[ UxBoD ]--" <ux...@splatnix.net>.
----- Original Message -----
> On Thu, Jan 20, 2011 at 3:10 PM, --[ UxBoD ]-- <ux...@splatnix.net>
> wrote:
> > ----- Original Message -----
> >> Did you set RewriteEngine on?
> >>
> >> Where do you define your rules? If there's a VirtualHost handling
> >> the
> >> request, they need to be defined there.
> >
> > Hello Eric,
> >
> > Thank you for the response. Yes it is a virtual host and I am using
> > the following directives for it:
> >
> > <VirtualHost *:80>
> >    ServerAdmin webmaster@somedomain.com
> >    DocumentRoot "/www/somedomain.com"
> >    <Directory /www/somedomain.com>
> >        AllowOverride All
> >    </Directory>
> >    ServerName www.somedomain.com
> >    ServerAlias somedomain.com www.somedomain.co.uk somedomain.co.uk
> >    ErrorLog "logs/www.somedomain.com-error.log"
> >    CustomLog "logs/www.somedomain.com-access.log" common
> > </VirtualHost>
> >
> > I have hardened Apache though I did try changing the directives in
> > httpd.conf for /www to have AllowOveride All as-well but to
> > no-avail. It seems odd though that a normal re-direct is working
> > fine.
> 
> Use the RewriteLog to debug.
> 

Any ideas Eric please ?

123.123.123.123 - - [20/Jan/2011:20:22:05 +0000] [www.somedomain.co.uk/sid#8893968][rid#b8b1640/initial] (1) [perdir /www/somedomain.com/] pass through /www/somedomain.com/
123.123.123.123 - - [20/Jan/2011:20:22:05 +0000] [www.somedomain.co.uk/sid#8893968][rid#b8f3e10/subreq] (1) [perdir /www/somedomain.com/] internal redirect with /index.php [INTERNAL REDIRECT]
123.123.123.123 - - [20/Jan/2011:20:22:05 +0000] [www.somedomain.co.uk/sid#8893968][rid#b8f5e20/subreq] (1) [perdir /www/somedomain.com/] pass through /www/somedomain.com/index.php

-- 
Thanks, Phil

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by Eric Covener <co...@gmail.com>.
On Thu, Jan 20, 2011 at 3:10 PM, --[ UxBoD ]-- <ux...@splatnix.net> wrote:
> ----- Original Message -----
>> Did you set RewriteEngine on?
>>
>> Where do you define your rules? If there's a VirtualHost handling the
>> request, they need to be defined there.
>
> Hello Eric,
>
> Thank you for the response. Yes it is a virtual host and I am using the following directives for it:
>
> <VirtualHost *:80>
>    ServerAdmin webmaster@somedomain.com
>    DocumentRoot "/www/somedomain.com"
>    <Directory /www/somedomain.com>
>        AllowOverride All
>    </Directory>
>    ServerName www.somedomain.com
>    ServerAlias somedomain.com www.somedomain.co.uk somedomain.co.uk
>    ErrorLog "logs/www.somedomain.com-error.log"
>    CustomLog "logs/www.somedomain.com-access.log" common
> </VirtualHost>
>
> I have hardened Apache though I did try changing the directives in httpd.conf for /www to have AllowOveride All as-well but to no-avail. It seems odd though that a normal re-direct is working fine.

Use the RewriteLog to debug.

--
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by Björn Zettergren <bj...@basefarm.se>.
On 01/20/2011 09:59 PM, Björn Zettergren wrote:
> As Eric wrote, you need to put your Rewrites inside the <VirtualHost>
> directive, i don't see them there in the above snippet. Possibly the
> "RewriteEngine On" needs to go there too.
>
> /Björn

Cheez, i failed to fetch all the latest messages before i posted. Sorry, 
my message did not take a whole lot of what you've said into account. :-)

/Björn

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by Björn Zettergren <bj...@basefarm.se>.
On 01/20/2011 09:10 PM, --[ UxBoD ]-- wrote:
> ----- Original Message -----
>> Did you set RewriteEngine on?
>>
>> Where do you define your rules? If there's a VirtualHost handling the
>> request, they need to be defined there.


> <VirtualHost *:80>
>      ServerAdmin webmaster@somedomain.com
>      DocumentRoot "/www/somedomain.com"
>      <Directory /www/somedomain.com>
>          AllowOverride All
>      </Directory>
>      ServerName www.somedomain.com
>      ServerAlias somedomain.com www.somedomain.co.uk somedomain.co.uk
>      ErrorLog "logs/www.somedomain.com-error.log"
>      CustomLog "logs/www.somedomain.com-access.log" common
> </VirtualHost>


As Eric wrote, you need to put your Rewrites inside the <VirtualHost> 
directive, i don't see them there in the above snippet. Possibly the 
"RewriteEngine On" needs to go there too.

/Björn

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by "--[ UxBoD ]--" <ux...@splatnix.net>.
----- Original Message -----
> Did you set RewriteEngine on?
> 
> Where do you define your rules? If there's a VirtualHost handling the
> request, they need to be defined there.

Hello Eric,

Thank you for the response. Yes it is a virtual host and I am using the following directives for it:

<VirtualHost *:80>
    ServerAdmin webmaster@somedomain.com
    DocumentRoot "/www/somedomain.com"
    <Directory /www/somedomain.com>
        AllowOverride All
    </Directory>
    ServerName www.somedomain.com
    ServerAlias somedomain.com www.somedomain.co.uk somedomain.co.uk
    ErrorLog "logs/www.somedomain.com-error.log"
    CustomLog "logs/www.somedomain.com-access.log" common
</VirtualHost>

I have hardened Apache though I did try changing the directives in httpd.conf for /www to have AllowOveride All as-well but to no-avail. It seems odd though that a normal re-direct is working fine.
-- 
Thanks, Phil

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by Eric Covener <co...@gmail.com>.
Did you set RewriteEngine on?

Where do you define your rules?  If there's a VirtualHost handling the
request, they need to be defined there.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by "--[ UxBoD ]--" <ux...@splatnix.net>.
----- Original Message -----
> On 01/21/2011 08:58 AM, Mark Wiltshire wrote:
> > Hi UxBoD
> >
> > Can you confirm you have
> >
> > RewriteCond
> > RewriteRule
> >
> > for each of you domains, I believe if you write multiple
> > RewriteCond, they all
> > have to match for the Rule then to be run.
> > Try in separate pairs.
> 
> mod_rewrite will default to do logical AND operations on consecutive
> RewriteCond, as UxBoD did, and added the [OR] option is correct, and
> will work.
> 
> /Björn
> 
Appreciate all the replies.  In the end I got it to work by changing the rule to:

RewriteCond %{HTTP_HOST} !=www.somedomain.com
RewriteRule ^ http://www.somedomain.com%{REQUEST_URI} [R=301,L]
-- 
Thanks, Phil

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by Björn Zettergren <bj...@basefarm.se>.
On 01/21/2011 08:58 AM, Mark Wiltshire wrote:
> Hi UxBoD
>
> Can you confirm you have
>
> RewriteCond
> RewriteRule
>
> for each of you domains, I believe if you write multiple RewriteCond, they all
> have to match for the Rule then to be run.
> Try in separate pairs.

mod_rewrite will default to do logical AND operations on consecutive 
RewriteCond, as UxBoD did, and added the [OR] option is correct, and 
will work.

/Björn

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite woes

Posted by Mark Wiltshire <ma...@redalertconsultants.co.uk>.
Hi UxBoD

Can you confirm you have

RewriteCond
RewriteRule

for each of you domains, I believe if you write multiple RewriteCond, they all have to match for the Rule then to be run.
Try in separate pairs.

R

Mark


On 20 Jan 2011, at 20:00, --[ UxBoD ]-- wrote:

Hello all,

I am switching from LiteSpeed webserver to Apache and having a real issue with mod_rewrite.  First of all here are the details of apache:

Server version: Apache/2.2.17 (Unix)
Server built:   Jan 20 2011 16:15:22
Server's Module Magic Number: 20051115:25
Server loaded:  APR 1.4.2, APR-Util 1.3.10
Compiled using: APR 1.4.2, APR-Util 1.3.10
Architecture:   64-bit
Server MPM:     Prefork
 threaded:     no
   forked:     yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-D HTTPD_ROOT="/usr/local/apache"
-D SUEXEC_BIN="/usr/local/apache/bin/suexec"
-D DEFAULT_PIDLOG="logs/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="logs/accept.lock"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"

I have included the necessary module:

LoadModule rewrite_module     modules/mod_rewrite.so

and have tested that it works by touching a file called test.html and making it redirect to another site using the following .htaccess rule:

Redirect /test/test.html http://httpd.apache.org

Now the issue comes when I am trying to redirect a domain URL in the following formats:

http://somedomain.com
http://somedomain.co.uk
http://www.somedomain.co.uk

and wish them all to be re-written as:

http://www.somedomain.com

I have tried using the following rule:

RewriteCond %{HTTP_HOST} ^somedomain.co.uk$ [NC,OR]
RewriteCond %{HTTP_HOST} ^somedomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.somedomain.co.uk$ [NC,OR]
RewriteRule ^(.*)$ http://www.somedomain.com/$1 [R=301,L]

But it always ends up just showing the domain I entered and not re-directing :(

Am I doing something really stupidly crazy as I do not have much more hair to pull out :) Looking for some kind assistance.
-- 
Thanks, Phil

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
  "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org



Regards

Mark

You can view my current Wolters Kluwer tasks at:
https://secure.nozbe.com/nozbe/page/feed/get-markRAC.5625.wolters_kluwer

You can view my calendar at:		   You can subscribe to my calendar at:
http://ical.me.com/markjwiltshire/Work    webcal://ical.me.com/markjwiltshire/Work.ics







Mark Wiltshire							Red Alert Consultants LTD
Director - Technical Web Consultant						Flat 6
									  168 Tower Bridge Road
												    London
											             SE1 3LS
mark@redalertconsultants.co.uk
iPhone email: markjwiltshire@me.com
IM: markjwiltshire@yahoo.com			    Desk:     0208 247 1547
http://www.redalertconsultants.co.uk	    Mobile: 07973 252 403





Re: [users@httpd] mod_rewrite woes

Posted by Joost de Heer <jo...@sanguis.xs4all.nl>.
On 01/20/2011 09:00 PM, --[ UxBoD ]-- wrote:
> Hello all,

> Now the issue comes when I am trying to redirect a domain URL in the following formats:
>
> http://somedomain.com
> http://somedomain.co.uk
> http://www.somedomain.co.uk
>
> and wish them all to be re-written as:
>
> http://www.somedomain.com
>
> I have tried using the following rule:
>
> RewriteCond %{HTTP_HOST} ^somedomain.co.uk$ [NC,OR]
> RewriteCond %{HTTP_HOST} ^somedomain.com$ [NC,OR]
> RewriteCond %{HTTP_HOST} ^www.somedomain.co.uk$ [NC,OR]
> RewriteRule ^(.*)$ http://www.somedomain.com/$1 [R=301,L]

Do you have 'RewriteEngine on'? Did you try turning on 
RewriteLog/RewriteLogLevel 9 ?

Joost

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org