You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Steve Blandford <st...@myecheck.com> on 2005/06/29 18:37:22 UTC

[users@httpd] mod_rewrite question(s)

I've been trying to use mod_rewrite to have http calls on a couple of 
directories and either all .php or one specific .php file rewritten as 
https calls.

I have been able to use <directory successfully to get the directories 
to rewrite but I cannot for the life of me get a rewrite of

http://www.domain.com/xxxx.php to rewrite to https://www.domain.com/xxxx.php

I am finding out just how tricky mod_rewrite and regular expressions can be.

Another problem I am seeing is even though I have logging turned on in 
my conf file, and that the log file was created, nothing has been 
written to it...

Here is the portion of my conf file relating to the problem. (domain 
names have been changed to protect the innocent)

        #    ServerName dummy-host.example.com
        #    ErrorLog logs/dummy-host.example.com-error_log
        #    CustomLog logs/dummy-host.example.com-access_log common
        #</VirtualHost>

        RewriteEngine On


        NameVirtualHost 10.0.0.3:80
         
        <VirtualHost 10.0.0.3:80>
            DocumentRoot /var/www/v1.domain.com/html/public
            ServerName www.domain.com
            RewriteLog "/var/log/httpd/rewrite_log"
            RewriteLogLevel 8
            ServerAlias *.domain.com *.domain.co.uk
            Alias /merchant /var/www/v1.domain.com/html/merchant
            Alias /admin /var/www/v1.domain.com/html/admin
            ScriptAlias /cgi-bin /var/www/v1.domain.com/cgi-bin
            ErrorLog /var/log/httpd/domain.com-error_log
            CustomLog /var/log/httpd/domain.com-access_log common
        </VirtualHost>

        # 1
        <Directory "/var/www/v1.domain.com/html/admin">
            Options FollowSymLinks
            AllowOverride All   
            RewriteCond %{HTTPS} !=on
            RewriteRule ^/(.*) https://%www.domain.com/$1 [R]
        </Directory>

        #2
        <Directory "/var/www/v1.domain.com/html/merchant">
            Options FollowSymLinks
            AllowOverride All
            RewriteCond %{HTTPS} !=on
            RewriteRule ^/(.*) https://%www.domain.com/$1 [R]
        </Directory>

        <Directory "/var/www/v1.domain.com/cgi-bin">
          SetHandler perl-script
          PerlResponseHandler ModPerl::Registry
          PerlOptions +ParseHeaders
          Options +ExecCGI
        </Directory>

The #1 and #2 ones work. currently. They take any request that is not 
https and convert it to https.


Any help is greatly appreciated!

Cheers
Steve Blandford




---------------------------------------------------------------------
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 question(s)

Posted by Steve Blandford <st...@myecheck.com>.
Fantastic!

I moved

RewriteEngine On
RewriteLog "/var/log/httpd/rewrite_log"
RewriteLogLevel 8

into the VirtualHost and the logging is now working. Many thanks!

The one thing left for me to accomplish is to either;

1. rewrite all .php requests as https

or

2. rewrite a specific http://......../xxx.php file as a https call

Thanks again for the speediness and accuracy of your reply Joshua!

Cheers
Steve

Joshua Slive wrote:

>On 6/29/05, Steve Blandford <st...@myecheck.com> wrote:
>  
>
>> 
>> Joshua,
>> 
>> thanks for the quick response. 
>> 
>> To address your comments;
>> 
>>  the  RewriteEngine On command is just above the Virtual host section (5th
>>line from the top of the snippet) 
>>    
>>
>
>I believe the RewriteEngine directive needs to be inside the virtual host.
>
>Joshua.
>
>---------------------------------------------------------------------
>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
>
>  
>


---------------------------------------------------------------------
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 question(s)

Posted by Joshua Slive <js...@gmail.com>.
On 6/29/05, Steve Blandford <st...@myecheck.com> wrote:
>  
>  Joshua,
>  
>  thanks for the quick response. 
>  
>  To address your comments;
>  
>   the  RewriteEngine On command is just above the Virtual host section (5th
> line from the top of the snippet) 

I believe the RewriteEngine directive needs to be inside the virtual host.

Joshua.

---------------------------------------------------------------------
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 question(s)

Posted by Steve Blandford <st...@myecheck.com>.
Joshua,

thanks for the quick response.

To address your comments;

 the  RewriteEngine On command is just above the Virtual host section 
(5th line from the top of the snippet)

I've removed the % signs and nothing changed in the operation of the 
rewrite. So the %age sign was superfluous.

Now since the engine is on, can you think of any reason the

            RewriteLog "/var/log/httpd/rewrite_log"
            RewriteLogLevel 8

isn't working?

Cheers
Steve



Joshua Slive wrote:

>On 6/29/05, Steve Blandford <st...@myecheck.com> wrote:
>  
>
>>Another problem I am seeing is even though I have logging turned on in
>>my conf file, and that the log file was created, nothing has been
>>written to it...
>>
>>Here is the portion of my conf file relating to the problem. (domain
>>names have been changed to protect the innocent)
>>
>>        #    ServerName dummy-host.example.com
>>        #    ErrorLog logs/dummy-host.example.com-error_log
>>        #    CustomLog logs/dummy-host.example.com-access_log common
>>        #</VirtualHost>
>>
>>        RewriteEngine On
>>
>>
>>        NameVirtualHost 10.0.0.3:80
>>
>>        <VirtualHost 10.0.0.3:80>
>>            DocumentRoot /var/www/v1.domain.com/html/public
>>            ServerName www.domain.com
>>            RewriteLog "/var/log/httpd/rewrite_log"
>>            RewriteLogLevel 8
>>            ServerAlias *.domain.com *.domain.co.uk
>>            Alias /merchant /var/www/v1.domain.com/html/merchant
>>            Alias /admin /var/www/v1.domain.com/html/admin
>>            ScriptAlias /cgi-bin /var/www/v1.domain.com/cgi-bin
>>            ErrorLog /var/log/httpd/domain.com-error_log
>>            CustomLog /var/log/httpd/domain.com-access_log common
>>        </VirtualHost>
>>
>>        # 1
>>        <Directory "/var/www/v1.domain.com/html/admin">
>>            Options FollowSymLinks
>>            AllowOverride All
>>            RewriteCond %{HTTPS} !=on
>>            RewriteRule ^/(.*) https://%www.domain.com/$1 [R]
>>        </Directory>
>>
>>        #2
>>        <Directory "/var/www/v1.domain.com/html/merchant">
>>            Options FollowSymLinks
>>            AllowOverride All
>>            RewriteCond %{HTTPS} !=on
>>            RewriteRule ^/(.*) https://%www.domain.com/$1 [R]
>>        </Directory>
>>
>>        <Directory "/var/www/v1.domain.com/cgi-bin">
>>          SetHandler perl-script
>>          PerlResponseHandler ModPerl::Registry
>>          PerlOptions +ParseHeaders
>>          Options +ExecCGI
>>        </Directory>
>>
>>The #1 and #2 ones work. currently. They take any request that is not
>>https and convert it to https.
>>    
>>
>
>I very much doubt that they are working like you think.  Probably some
>other configuration is having that effect.  I see several problems:
>1. No "RewriteEngine On", which could explain why you have nothing in
>your RewriteLog.
>2. What is the "%" sign doing in the target URL?
>3. When inside <Directory> sections, the URL you are matching against
>generally doesn't have a leading slash.  I always find it much simpler
>to keep my RewriteRules out of <Directory> sections and just put the
>directory in the RewriteRule itself, as in
>
>RewriteEngine On
>RewriteCond %{HTTPS} !=on
>RewriteRule ^/merchant(.*) https://%www.domain.com/merchant$1
>
>Joshua.
>
>---------------------------------------------------------------------
>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 question(s)

Posted by Joshua Slive <js...@gmail.com>.
On 6/29/05, Steve Blandford <st...@myecheck.com> wrote:
> Another problem I am seeing is even though I have logging turned on in
> my conf file, and that the log file was created, nothing has been
> written to it...
> 
> Here is the portion of my conf file relating to the problem. (domain
> names have been changed to protect the innocent)
> 
>         #    ServerName dummy-host.example.com
>         #    ErrorLog logs/dummy-host.example.com-error_log
>         #    CustomLog logs/dummy-host.example.com-access_log common
>         #</VirtualHost>
> 
>         RewriteEngine On
> 
> 
>         NameVirtualHost 10.0.0.3:80
> 
>         <VirtualHost 10.0.0.3:80>
>             DocumentRoot /var/www/v1.domain.com/html/public
>             ServerName www.domain.com
>             RewriteLog "/var/log/httpd/rewrite_log"
>             RewriteLogLevel 8
>             ServerAlias *.domain.com *.domain.co.uk
>             Alias /merchant /var/www/v1.domain.com/html/merchant
>             Alias /admin /var/www/v1.domain.com/html/admin
>             ScriptAlias /cgi-bin /var/www/v1.domain.com/cgi-bin
>             ErrorLog /var/log/httpd/domain.com-error_log
>             CustomLog /var/log/httpd/domain.com-access_log common
>         </VirtualHost>
> 
>         # 1
>         <Directory "/var/www/v1.domain.com/html/admin">
>             Options FollowSymLinks
>             AllowOverride All
>             RewriteCond %{HTTPS} !=on
>             RewriteRule ^/(.*) https://%www.domain.com/$1 [R]
>         </Directory>
> 
>         #2
>         <Directory "/var/www/v1.domain.com/html/merchant">
>             Options FollowSymLinks
>             AllowOverride All
>             RewriteCond %{HTTPS} !=on
>             RewriteRule ^/(.*) https://%www.domain.com/$1 [R]
>         </Directory>
> 
>         <Directory "/var/www/v1.domain.com/cgi-bin">
>           SetHandler perl-script
>           PerlResponseHandler ModPerl::Registry
>           PerlOptions +ParseHeaders
>           Options +ExecCGI
>         </Directory>
> 
> The #1 and #2 ones work. currently. They take any request that is not
> https and convert it to https.

I very much doubt that they are working like you think.  Probably some
other configuration is having that effect.  I see several problems:
1. No "RewriteEngine On", which could explain why you have nothing in
your RewriteLog.
2. What is the "%" sign doing in the target URL?
3. When inside <Directory> sections, the URL you are matching against
generally doesn't have a leading slash.  I always find it much simpler
to keep my RewriteRules out of <Directory> sections and just put the
directory in the RewriteRule itself, as in

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/merchant(.*) https://%www.domain.com/merchant$1

Joshua.

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