I would like to 301 redirect the following URL
www.domain.com/Gallery2/v/South/Actress/Ritu+Kaur+Actress+Photos
to
www.domain.com/gallery/ritu-kaur.html
I tried the following, but not worked,
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^Gallery2\/v\/South\/Actress\/Ritu\+Kaur\+Actress\+Photos\/$ "http\:\/\/www\.indiancinemagallery\.com\/gallery\/ritu\-kaur\.html" [R=301,L]
Please advise
Place this rule in your Gallery2/.htaccess before any other rewrite rule
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^v/South/Actress/Ritu\+Kaur\+Actress\+Photos/?$ http://www.indiancinemagallery.com/gallery/ritu-kaur.html [R=301,L,NC]
The + signs will probably get canonicalized to spaces, try replacing them with spaces instead:
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^Gallery2/v/South/Actress/Ritu\ Kaur\ Actress\ Photos/$ http://www.indiancinemagallery.com/gallery/ritu-kaur.html [L,R=301]
The URI is decoded before being put through matching against regex in RewriteRule's, so unless your url had encoded + signs, then they'll get decoded to spaces instead.
Related
I'm redirecting a http www. URL to a new non-www. domain at https, but one particular URL pattern has changed in structure, so I'd like to use a ReWrite Rule for it in htaccess.
Old:
http://www.example.com/travel.php?cat=cat1&id=1&title=title-string
http://www.example.com/travel/cat1/1/title-string
New:
https://newdomain.com/travel/cat1-title-string
So for the redirect, the "id" parameter disappears completely, but I'd like the "cat" parameter and hyphen to prefix the "title" parameter in the new URL.
I think this is possible, but I can't figure out how? If it isn't, I'll settle for a rule without the cat parameter:
https://newdomain.com/travel/title-string
I would like to use an or expression to match the "cat":
(cat1|cat2|cat3)
For the first kind of URL you do this:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^cat=([^&]*)&id=[^&]*&title=(.*)?$ [NC]
RewriteRule ^travel\.php$ https://newdomain.com/travel/%1-%2? [R=301,L]
For the second URL you do this:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} ^\/travel\/([^\/]*)\/[^\/]*\/(.*)?$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/travel/%1-%2 [R=301,L]
If cat1 is should only be work for some spezial values we have to redefine this:
For the first kind of URL you do this:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^cat=(cat1|cat2|cat3)&id=[^&]*&title=(.*)?$ [NC]
RewriteRule ^travel\.php$ https://newdomain.com/travel/%1-%2? [R=301,L]
For the second URL you do this:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} ^\/travel\/(cat1|cat2|cat3)\/[^\/]*\/(.*)?$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/travel/%1-%2 [R=301,L]
Replace cat1|cat2|cat3 with your values
RewriteEngine on
RewriteCond %{HTTP_HOST} ^test\.hemsida\.eu$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.hemsida\.eu$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ "https\:\/\/testar\.se\/sv/$1" [R=301,L]
So this one will redirect all traffic from test.hemsida.eu to https://testar.se/sv/$1
But the problem is if test.hemsida.eu contains sv in the path, it redirects: https://testar.se/sv/sv/test
How can I get rid of one the sv, but still maintain it, if it isn't present in the URL?
You can use it like this by tweaking your regex:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?test\.hemsida\.eu$ [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ [NC]
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ [NC]
RewriteRule ^(?:sv/)?(.*)$ https://testar.se/sv/$1 [NC,NE,R=301,L]
(?:sv/)? (optional match) at the start of pattern will make sure that you always capture whatever comes after /sv/ or if there no /sv/ then complete match.
I want to make mod rewrite as the following example :
from google.com.mydomain.com to mydomain.com/index.php?domain=google.com
I use like
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteCond %{QUERY_STRING} !domain=
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain.com$ [NC]
RewriteRule ^(.*)$ /index.php?domain=%1 [L,QSA]
but this redirect google.mydomain.com to mydomain.com/index.php?domain=google
I want rule to redirect google.com not google
thanks
It is due to the incorrect regex. Try this rule:
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteCond %{QUERY_STRING} !domain=
RewriteCond %{HTTP_HOST} ^(.+?)\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ /index.php?domain=%1 [L,QSA]
In your rule you're using [^\.]+ which matched until a dot is found therefore it is matching google instead of google.com.
I already have a rule set up to remove www from my urls and redirect them...
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*) http://'%'1$1 [R=301,L]
*note-I had to put quotes around the percent sign to post this message, the actual rule does not contain them.
I now want to also strip off any trailing /
How would I do this?
Add an extra rule:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ $1 [L,R=301]
I have to addresses for one site (different langs) and I need a redirect with saving query string. So I need to catch this
http://www.example1.kereell.com/wp-login.php?action=logout&redirect_to=http%253A%252F%252Fwww.example2.kereell.com%252Fafiliados-de-la-zona%252F&_wpnonce=66909cdca0
and redirect to
http://www.example2.kereell.com/wp-login.php?action=logout&redirect_to=http%253A%252F%252Fwww.example2.kereell.com%252Fafiliados-de-la-zona%252F&_wpnonce=66909cdca0
in .htaccess file it should be something like this
RewriteCond %{HTTP_HOST} ^.*example1\.kereell\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/wp-login.php?action=logout&redirect_to=http%3A%2F%2Fwww.example2.kereell.com%2Fafiliados-de-la-zona%2F&_wpnonce=66909cdca0$ [NC]
RewriteRule ^(.*)$ http://www.example2.kereell.com/$1 [R=301,L]
I tried a lot of everything (escaping "%", regex classes) but didn't get it to work because of urlencoded characters. If I replace all urlencoded symbols - it works..
So the solution was really easy as it suppose to be:
RewriteCond %{HTTP_HOST} ^.*example1\.kereell\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/wp-login.php$ [NC]
RewriteCond %{QUERY_STRING} ^action=logout&redirect_to=http[\%A-Z0-9]*www.example2.kereell.com(.*)$ [NC]
RewriteRule ^(.*)$ http://www.example2.kereell.com/$1 [R=301,L]
Thanks for Qtax that paid my attention to QUERY_STRING!