You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Stefan Moravcik <sm...@it-con.org> on 2011/05/10 11:03:02 UTC
[users@httpd] rewrite condition problem
Hello list,
I want to do a rewrite rule for all URLs to get rewritten to example.com
This works and can be done with very simple rule:
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^/(.*) http://www.example.com/$1 [R=301,L]
The problem is, when i want to exclude a URI.
So the scenario is to rewrite all TLDs to .com except those with
/free_trial[1-11]?
The rule should look like follow:
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/free_trial[1-9]?1?
RewriteRule ^/(.*) http://www.example.com/$1 [R=301,L]
For some reason this doesn't work. The regex is ok, when i delete "!"
not char, everything works as expected. If the domain is not .com and
the URI is free_trial to freetrial11, it will get rewritten, everything
else is not. So i used the ! to get the revert result, everything get
rewritten except free_trial to free_trial11. But with ! in place,
everything including free_trials pages will get rewritten. It looks like
REQUEST_URI with ! is ignored completely. Any suggestion how i could
make this work or any idea, why my rewrite condition doesn't work.
Best Regards,
Stefan
---------------------------------------------------------------------
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] rewrite condition problem
Posted by Stefan Moravcik <sm...@it-con.org>.
Great, thank you very much, it helped. I forgot about drupal's nice URLs
rewrite rules in .htaccess.
Drupal has been rewriting ^/free_trial$ to ^/index.php?q=free_trial
so the final working solution is
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/free_trial[1-9]?[1]? [OR]
RewriteCond %{REQUEST_URI} ^/index.php$
RewriteCond %{QUERY_STRING} !^q=free_trial[1-9]?[1]?
RewriteRule ^/(.*) http://www.example.com/$1 [R=301,L]
On 10/05/2011 12:52, Eric Covener wrote:
>> . Any suggestion how i could make this work or any idea,
>> why my rewrite condition doesn't work.
> RewriteLog
>
> ---------------------------------------------------------------------
> 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] rewrite condition problem
Posted by Eric Covener <co...@gmail.com>.
>. Any suggestion how i could make this work or any idea,
> why my rewrite condition doesn't work.
RewriteLog
---------------------------------------------------------------------
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