I'd like my site to be accessible by the following two urls only:
http://domain.com
http://origin.domain.com
But the following rewrite rule gets into an infinite loop:
RewriteCond %{HTTP_HOST} !^(origin)\.domain\.com [NC]
RewriteRule (.*) http://domain.com$1 [R=301,L]
What am I doing wrong? Any help would be greatly appreciated!
Change the first line to
RewriteCond %{HTTP_HOST} !^(origin)?\.?domain\.com [NC]
Related
I want to redirect all url's from
domain.com/incoming-dir/ to domain.com/direct-dir/
I use the following for this:
RewriteEngine On
RewriteRule ^/?incoming-dir/(.*) direct-dir/$1 [R=301,L]
But now I want to build in an exception.
The redirect should not happen for an iPhone and iPad.
What should be added for this exception?
You should check first with %{HTTP_USER_AGENT} and exclude what you want from next rule
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !^.*(iPhone|iPad).*$ [NC]
RewriteRule ^incoming-dir/(.*) direct-dir/$1 [R=301,L]
I have a url that can look like
domain.com/f1/v1/f2/v2/f3/v3/f4/v4/f5/v5/f6/v6
with variations of lesser counts such as
domain.com/f1/v1/f2/v2/f3/v3/f4/v4/f5/v5
domain.com/f1/v1/f2/v2/f3/v3/f4/v4
domain.com/f1/v1/f2/v2/f3/v3
domain.com/f1/v1/f2/v2
domain.com/f1/v1
how can i build a rewrite rule that will construct the following
domain.com/models?f1=v1&f2=v2...f6=v6
this website is an IIS 6 MVC 3 application using Helicon Isapi_Rewrite for url rewrites.
The best way is to create a set of rules each rule will process 1 pair, 2 pairs, 3 pairs of paraters...
RewriteEngine on
RewriteBase /
# rule for one pair of parameters
RewriteCond %{HTTP:Host} ^domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)$ /models?$1=$2 [NC,L]
# rule for two pairs of parameters
RewriteCond %{HTTP:Host} ^domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ /models?$1=$2&$3=$4 [NC,L]
I came up with this solution using a map. The main problem I had was exceeding the $1-$9 limitation on placeholders.
RewriteMap filtermap txt:content/maps/filtermap.txt [NC]
RewriteCond ${filtermap:$6|NOT_FOUND} !NOT_FOUND [NC]
RewriteRule ^models/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*) /models/?${filtermap:$1}&${filtermap:$2}&${filtermap:$3}&${filtermap:$4}&${filtermap:$5}&${filtermap:$6} [NC,L]
RewriteCond ${filtermap:$5|NOT_FOUND} !NOT_FOUND [NC]
RewriteRule ^models/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*) /models/?${filtermap:$1}&${filtermap:$2}&${filtermap:$3}&${filtermap:$4}&${filtermap:$5} [NC,L]
RewriteCond ${filtermap:$4|NOT_FOUND} !NOT_FOUND [NC]
RewriteRule ^models/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*) /models/?${filtermap:$1}&${filtermap:$2}&${filtermap:$3}&${filtermap:$4} [NC,L]
RewriteCond ${filtermap:$3|NOT_FOUND} !NOT_FOUND [NC]
RewriteRule ^models/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*) /models/?${filtermap:$1}&${filtermap:$2}&${filtermap:$3} [NC,L]
RewriteCond ${filtermap:$2|NOT_FOUND} !NOT_FOUND [NC]
RewriteRule ^models/([^/]*/[^/]*)/([^/]*/[^/]*) /models/?${filtermap:$1}&${filtermap:$2} [NC,L]
RewriteCond ${filtermap:$1|NOT_FOUND} !NOT_FOUND [NC]
RewriteRule ^models/([^/]*/[^/]*) /models/?${filtermap:$1} [NC,L]
Its not super pretty but it does work. The filter map looks like this
p1/v1 p1=v1
p2/v2 p2=v2
...
This is not an ideal solution if your combinations of p1/v1 are unlimited, but mine are finite so its pretty easy to manage.
how to create rewrite rule for that url like
http://www.abc.in/subfoldername/index.php?alist&TP=xyz&ct=bcd
to
http://bcd.abc.in
Enter this following code to .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9_-]+)\.(.+)$
RewriteRule ^$ http://%{HTTP_HOST}/subfoldername/index.php?alist&TP=xyz&ct=%2 [L]
I have a multilingual blog, default language is Italian and second language is English.
So I have 2 RSS feeds:
/feed
/feed/?lang=en
The first points to Italian the second to English.
I wanna both redirect to Feedburner using .htaccess, the first should point to http://feeds.feedburner.com/SimoBlog and the second to http://feeds.feedburner.com/digitalking/haPl
I successfully done it for the first with this code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]
RewriteRule ^feed/?.*$ http://feeds.feedburner.com/SimoBlog [L,NC,R=302]
</IfModule>
I don't figure out to make it working also for the second feed URL, any help?
Thanks, Simone
You could check if the query string is equal to lang=en:
RewriteCond %{HTTP_USER_AGENT} !(FeedBurner|FeedValidator) [NC]
RewriteCond %{QUERY_STRING} !=lang=en
RewriteRule ^feed/?$ http://feeds.feedburner.com/SimoBlog [L,NC,R=302]
RewriteCond %{HTTP_USER_AGENT} !(FeedBurner|FeedValidator) [NC]
RewriteCond %{QUERY_STRING} =lang=en
RewriteRule ^feed/?$ http://feeds.feedburner.com/digitalking/haPl [L,NC,R=302]
I wanted to achieve this
example.com/search_results/?action=search&username[equal]=PorscheSA
to
example.com/PorscheSA
I have used .htaccess for many websites to achieve this, but since this website is smarty based, it doesn't seem to work. Any help will be much appreciated.
Ok, this is the .htaccess file:
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php
In order to achieve the following I tried this:
RewriteRule ^([a-zA-Z0-9-_+^/])/$ /search_results/?action=search&username[equal]=$1
and nothing happened.
Your question is still a little vague as to what exactly you expect to have happen, but since you've posted your .htaccess, I'll take a stab at it and see if I get what you were after.
The most obvious reason that your RewriteRule isn't working is that your test pattern doesn't match the URL you've provided as an example, as your RewriteRule requires a trailing slash (and only matches one character before that). Additionally, if you put it after the rules that you currently have in your .htaccess file, it will never match because the request will have already been rewritten to index.php.
I think that you want something like this...
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} =www.example.com [NC]
RewriteRule ^.*$ http://example.com/$0 [L,R=301]
# Make sure we end and force the redirect so %{REQUEST_FILENAME} gets changed
RewriteRule ^[a-zA-Z0-9-_+^/]+$ search_results/?action=search&username[equal]=$0 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
However, if the search_results/ directory doesn't exist, then this is just going to be rewritten to index.php anyway, so I'm not sure what the purpose of the redirection would be in that case. And, if it does exist, since your test pattern matches pretty much anything I'd expect to see in a site path, then everything will be rewritten to the search_results/ directory, so very little (if anything) will end up at your site root's index.php.
Based on that, I feel like maybe there's some other criteria that you may have left out, but I could be wrong.