There are a few redirect rules for pages with query strings
RewriteCond %{QUERY_STRING} ^PAGEN_1=1 [NC]
RewriteRule ^news/$ http://www.mysite.ru/news/$ [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=1 [NC]
RewriteRule ^news/$ http://www.mysite.ru/news/$ [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=2 [NC]
RewriteRule ^news/$ http://www.mysite.ru/news/?PAGEN_1=2 [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=3 [NC]
RewriteRule ^news/$ http://www.mysite.ru/news/?PAGEN_1=3 [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=4 [NC]
RewriteRule ^news/$ http://www.mysite.ru/news/?PAGEN_1=4 [R=301,L]
RewriteCond %{QUERY_STRING} ^PAGEN_1=1 [NC]
RewriteRule ^articles/2/$ http://www.mysite.ru/articles/2/ [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=1 [NC]
RewriteRule ^articles/2/$ http://www.mysite.ru/articles/2/ [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=2 [NC]
RewriteRule ^articles/2/$ http://www.mysite.ru/articles/2/?PAGEN_1=2 [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=3 [NC]
RewriteRule ^articles/2/$ http://www.mysite.ru/articles/2/?PAGEN_1=3 [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=4 [NC]
RewriteRule ^articles/2/$ http://www.mysite.ru/articles/2/?PAGEN_1=4 [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=5 [NC]
RewriteRule ^articles/2/$ http://www.mysite.ru/articles/2/?PAGEN_1=5 [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=6 [NC]
RewriteRule ^articles/2/$ http://www.mysite.ru/articles/2/?PAGEN_1=6 [R=301,L]
Is there any way to write these rules in common, not for every query string?
UPD
I used this code
RewriteCond %{QUERY_STRING} ^PAGEN_1=1 [NC]
RewriteRule ^news/$ http://www.mysite.ru/news/$ [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=1 [NC]
RewriteRule ^news/$ http://www.mysite.ru/news/$ [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=([0-9]*)$ [NC]
RewriteRule ^news/(.*)$ http://www.mysite.ru/news/?PAGEN_1=%1 [R=301,L]
RewriteCond %{QUERY_STRING} ^PAGEN_1=1 [NC]
RewriteRule ^articles/2/$ http://www.mysite.ru/articles/2/ [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=1 [NC]
RewriteRule ^articles/2/$ http://www.mysite.ru/articles/2/ [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=([0-9]*)$ [NC]
RewriteRule ^articles/2/(.*)$ http://www.mysite.ru/articles/2/?PAGEN_1=%1 [R=301,L]
but I'm not sure about it. It works but I think maybe it should be simpler.
You can use:
RewriteCond %{QUERY_STRING} (?:^|&)PAGEN_1=1(?:&|$) [NC]
RewriteRule ^news/?$ http://www.mysite.ru/news/? [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=(\d+)(?:&|$) [NC]
RewriteRule ^news/?$ http://www.mysite.ru/news/?PAGEN_1=%1 [R=301,L]
RewriteCond %{QUERY_STRING} (?:^|&)PAGEN_1=1(?:&|$) [NC]
RewriteRule ^articles/(\d+)/?$ http://www.mysite.ru/articles/$1/? [R=301,L]
RewriteCond %{QUERY_STRING} ^&PAGEN_1=(\d+)(?:&|$) [NC]
RewriteRule ^articles/(\d+)/?$ http://www.mysite.ru/articles/$1/?PAGEN_1=%1 [R=301,L]
Related
i just want to know how to combine this two conditional format in one htaccess
SSL Https active Force non-wwwRewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Hide extension
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
maybe like this?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
I am helping with a project and noticed the following rules in the .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-projectdomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old-projectdomain.com$
RewriteRule (.*)$ https://www.new-projectdomain.com/$1 [R=301,L]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I'm not an expert on this but it looks somewhat redundant, I just can't put my finger on it.Can it be simplified?
You can use a single rule like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?old-projectdomain\.com$ [NC]
RewriteRule ^ https://www.new-projectdomain.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
We have merged 2 sites and have to organise redirects from the domain that is now not in use.
The domain aquarestaurantblackheath.co.uk redirects fine, but not the old urls from that domain.
Any suggestions. see my code...
Working
RewriteCond %{HTTP_HOST} ^aquarestaurantblackheath\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.aquarestaurantblackheath\.co\.uk$
RewriteRule ^/?$ "http\:\/\/www\.aquabarandgrill\.co\.uk\/section\/3\/1\/restaurant\-blackheath" [R=301,L]
Not working
RewriteCond %{HTTP_HOST} ^aquarestaurantblackheath\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.aquarestaurantblackheath\.co\.uk$
RewriteRule ^section\/8\/1\/location$ "http\:\/\/www\.aquabarandgrill\.co\.uk\/section\/10\/1\/restaurant" [R=301,L]
RewriteCond %{HTTP_HOST} ^aquarestaurantblackheath\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.aquarestaurantblackheath\.co\.uk$
RewriteRule ^section\/6\/1\/wines$ "http\:\/\/www\.aquabarandgrill\.co\.uk\/section\/8\/1\/food\-wine\-blackheath" [R=301,L]
RewriteCond %{HTTP_HOST} ^aquarestaurantblackheath\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.aquarestaurantblackheath\.co\.uk$
RewriteRule ^section\/7\/1\/reservations$ "http\:\/\/www\.aquabarandgrill\.co\.uk\/section\/3\/1\/restaurant\-blackheath" [R=301,L]
The entire htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^aquabarandgrill.co.uk [NC]
RewriteRule ^(.*)$ http://www.aquabarandgrill.co.uk/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.aquabarandgrill.co.uk/ [R=301,L]
RewriteRule ^index\.html$ http://www.aquabarandgrill.co.uk/ [R=301,L]
RewriteRule ^index\.htm$ http://www.aquabarandgrill.co.uk/ [R=301,L]
RewriteEngine on
Options +SymlinksIfOwnerMatch +MultiViews
RewriteRule ^(.*).php/(.*) $1.php?$2
## Bromley old site REDIRECTS (PERMANANT 301) ##
RewriteRule ^Home.php?id=Menus/?$ http://www.aquabarandgrill.co.uk/section/2/1/restaurant-bromley/ [L,R=301,NC]
#
## Deafult character encoding UTF-8 / ISO-8859-1
AddDefaultCharset ISO-8859-1
RewriteEngine On
RewriteCond %{HTTP_HOST} ^aquarestaurantblackheath\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.aquarestaurantblackheath\.co\.uk$
RewriteRule ^/?$ "http\:\/\/www\.aquabarandgrill\.co\.uk\/section\/3\/1\/restaurant\-blackheath" [R=301,L]
RewriteCond %{HTTP_HOST} ^aquabrasseriecroydon\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.aquabrasseriecroydon\.com$
RewriteRule ^/?$ "http\:\/\/www\.aquabarandgrill\.co\.uk\/section\/4\/1\/restaurant\-croydon" [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^(/?|section/7/1/reservations)$ http://www.aquabarandgrill.co.uk/section/3/1/restaurant-blackheath [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^section\/8\/1\/location$ http://www.aquabarandgrill.co.uk/section/10/1/restaurant [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^section\/6\/1\/wines$ http://www.aquabarandgrill.co.uk/section/8/1/food-wine-blackheath [R=301,L]
Try the following rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^(/?|section/7/1/reservations)$ http://www.aquabarandgrill.co.uk/section/3/1/restaurant-blackheath [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^section/8/1/location$ http://www.aquabarandgrill.co.uk/section/10/1/restaurant [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^section/6/1/wines$ http://www.aquabarandgrill.co.uk/section/8/1/food-wine-blackheath [R=301,L]
EDIT
After seeing the whole htaccess file, remove everything in there, and replace the whole file with the following piece of code:
AddDefaultCharset ISO-8859-1
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^(/?|section/7/1/reservations)$ http://www.aquabarandgrill.co.uk/section/3/1/restaurant-blackheath [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^section/8/1/location$ http://www.aquabarandgrill.co.uk/section/10/1/restaurant [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^section/6/1/wines$ http://www.aquabarandgrill.co.uk/section/8/1/food-wine-blackheath [R=301,L]
RewriteRule ^(.*)\.php/(.*) $1.php?$2 [L]
i am trying to implement dynamic
RewriteEngine on
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^/?$ /live/agent/index.php?agent_user_name=%1 [L]
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^(.+?)/?$ /live/agent/$1.php?agent_user_name=%1 [L]
Now this .htaccess converts
http://mydomain.com/live/agent/index.php?agent_user_name=username to http://username.mydomain.com
and
http://mydomain.com/live/agent/forum.php?agent_user_name=username to http://username.mydomain.com/form/
However, there are other pages as well which i want to redirect to subdomain like
http://mydomain.com/live/agent/view_blog.php?agent_user_name=username&blog_id=19 this page should be read via subdomain something like http://username.mydomain.com/view_blog/19 etc and also
http://mydomain.com/live/agent/page.php?agent_user_name=username&content_id=19 this page should be accessed by http://username.mydomain.com/content/19 etc
Thanks
This should work:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^content/([0-9]+)/?$ /live/agent/page.php?agent_user_name=%1&blog_id=$1 [L,QSA]
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^([^/]+)/([0-9]+)/?$ /live/agent/$1.php?agent_user_name=%1&blog_id=$2 [L,QSA]
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^/?$ /live/agent/index.php?agent_user_name=%1 [L]
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^(.+?)/?$ /live/agent/$1.php?agent_user_name=%1 [L]
Add the following below your current rules should achieve what you want.
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /live/agent/view_blog.php\?agent_user_name=(.*)&blog_id=(.*)\ HTTP
RewriteRule ^ http://%2.mydomain.com/view_blog/%3? [R,L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /live/agent/page.php\?agent_user_name=(.*)&content_id=(.*)\ HTTP
RewriteRule ^ http://%2.mydomain.com/content/%3? [R,L]
I have website http://paweljanicki.pl/Realizacje/.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^paweljanicki.pl$ [NC]
RewriteRule ^(.*)$ http://paweljanicki.pl/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://paweljanicki.pl/$1/ [L,R=301]
RewriteCond %{REQUEST_URI} ^\/Realizacje.aspx$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ /Realizacje/ [L,R=301]
RewriteCond %{REQUEST_URI} ^\/Kontakt.aspx$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ /Kontakt/ [L,R=301]
RewriteCond %{REQUEST_URI} ^\/Galeria.aspx$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ /Galeria/ [L,R=301]
RewriteCond %{REQUEST_URI} ^\/Linki.aspx$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ /Linki/ [L,R=301]
RewriteCond %{REQUEST_URI} ^\/Mapa-strony.aspx$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ /Mapa-strony/ [L,R=301]
RewriteCond %{REQUEST_URI} ^\/Galeria.aspx$
RewriteCond %{QUERY_STRING} ^gId=([0-9]*)$
RewriteRule ^(.*)$ /Galeria/%1/? [L,R=301]
RewriteCond %{REQUEST_URI} ^\/Galeria.aspx$
RewriteCond %{QUERY_STRING} ^gId=([0-9]*)&sgId=([0-9]*)$
RewriteRule ^(.*)$ /Galeria/%1/%2/? [L,R=301]
RewriteCond %{REQUEST_URI} ^\/Galeria.aspx$
RewriteCond %{QUERY_STRING} ^gId=([0-9]*)&sgId=([0-9]*)&pId=([0-9]*)$
RewriteRule ^(.*)$ /Galeria/%1/%2/%3/? [L,R=301]
RewriteRule ^Galeria/$ Galeria.aspx [L]
RewriteRule ^Galeria/([^/]+)/?$ Galeria.aspx?gId=$1 [L]
RewriteRule ^Galeria/([^/]+)/([^/]+)/?$ Galeria.aspx?gId=$1&sgId=$2 [L]
RewriteRule ^Galeria/([^/]+)/([^/]+)/([^/]+)/?$ Galeria.aspx?gId=$1&sgId=$2&pId=$3 [L]
RewriteCond %{REQUEST_URI} ^\/Realizacje.aspx$
RewriteCond %{QUERY_STRING} ^gId=([0-9]*)$
RewriteRule ^(.*)$ /Realizacje/%1/? [L,R=301]
RewriteRule ^Realizacje/$ Realizacje.aspx [L]
RewriteRule ^Realizacje/([^/]+)/?$ Realizacje.aspx?pId=$1 [L]
RewriteRule ^Kontakt/$ Kontakt.aspx [L]
RewriteRule ^Linki/$ Linki.aspx [L]
RewriteRule ^Mapa-strony/$ Mapa-strony.aspx [L]
RewriteCond %{REQUEST_URI} ^\/Programy-na-Zlecenie/$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ /Pisanie-Programow-na-Zamowienie/ [L,R=301]
#to use relative paths in RewriteMap, map files must reside in the same folder as .htaccess
#http://www.helicontech.com/ape/doc/mod_rewrite.htm
RewriteMap mapfile txt:mapfile.txt [NC]
RewriteMap revmapfile txt_rev:mapfile.txt [NC]
#RewriteCond %{QUERY_STRING} (.+)
#RewriteRule ^Default\.aspx$ ${mapfile:%1}? [NC,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ Default.aspx?${revmapfile:$1} [NC,L,NS]