Re: Issue with trailing slashes after rewrite

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



RewriteCond %{HTTP_HOST} ^foo\.mydomain\.com$
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^/(.*) /foo/$1 [L]

sorry missed the ^ above.

On Sat, Mar 17, 2012 at 1:49 PM, Igor Cicimov <icicimov@xxxxxxxxx> wrote:
First SERVER_NAME is apache internal NOT a http header sent with the request thus will match ANY request. Use HTTP_HOST instead. You also need to escape the dots in the host name.

Second, from the documentation:

"To combine new and old query strings, use the [QSA] flag."

so by using QSA you are modifying the query string adding another foo to it thus the result you are seeing.

Finally, your rules should look like:

RewriteCond %{HTTP_HOST} ^foo\.mydomain\.com$

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule /(.*) /foo/$1 [L]

Igor


On Sat, Mar 17, 2012 at 1:40 AM, Nala Gnirut <nala.gnirut@xxxxxxxxx> wrote:
Hi all,
in a shared hosting with no access to httpd.conf, I'm trying to redirect subdomains to different document root using mod_rewrite.

I'm using this rule in a .htaccess file placed in DocumentRoot:

# Change document root for foo.mydomain.com
RewriteCond %{SERVER_NAME} foo.mydomain.com
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule .* /foo%{REQUEST_URI} [QSA,L]

This works as expected accessing

foo.mydomain.com
foo.mydomain.com/
foo.mydomain.com/bar/

while

foo.mydomain.com/bar

fails as it's redirected to

/foo/foo/bar instead of /foo/bar

Please note that trailing slashes are automatically added to any rule but the ones rewritten by this rule.

Where's my fault?

Thanks in advance.




[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux