I would like to redirect this url:
http://www.domena.pl/?tekst,123.html
to this
http://www.domena.pl/tekst,123.html
I just want to remove ? after first /, so I would like to redirect every url domena/?...... to domena/......
I was using this htaccess and it works for domena/testtekst,123, but I don't know how I should change it to work with special character ?
RewriteCond %{HTTP_HOST} ^www.domena.pl$
RewriteCond %{REQUEST_URI} ^/test(.*)$
RewriteRule ^test(.*)$ http://www.domena.pl/$1 [L,R=301]
This does not work:
RewriteCond %{HTTP_HOST} ^www.domena.pl$
RewriteCond %{REQUEST_URI} ^/?(.*)$
RewriteRule ^?(.*)$ http://www.domena.pl/$1 [L,R=301]
and this doesn't work too:
RewriteCond %{HTTP_HOST} ^www.domena.pl$
RewriteCond %{REQUEST_URI} ^/\?(.*)$
RewriteRule ^\?(.*)$ http://www.domena.pl/$1 [L,R=301]
You can use:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+\?([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]
Related
My htaccess actually looks like :
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com(.)*$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^(.*)/$ /$1 [R=301,L]
RewriteRule ^([0-9a-zA-Z/\ -]+)(?:&([0-9a-zA-Z&=_\ -]+))?$ index.php?action=$1&$2 [L]
# $1 : route name and framework parameters
# $2 : classic $_GET parameters (¶m=value)
It redirects to https, then redirect to url without trailing slashes, then rewrite a clean url without index etc.
I would like to know, if I enter http://www.example.com/somepage/, how to redirect to https://example.com/somepage in a single redirection instead of multiple?
I would like to know, if I enter http://example.com/somepage/, how to redirect to https://example.com/somepage in a single redirection instead of two?
You can use this single redirect rule for that:
DirectoryIndex index.php
RewriteEngine On
# add https, remove www and remove trailing slash in same rule
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{REQUEST_URI} /$
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(.*?)/?$ https://%1/$1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ index.php?action=$0 [L,QSA]
Im trying to redirect several urls with 3 parameters to different static urls with .htaccess but nothing working.
1.
http://olddomain.com/index.php?id_category=28&controller=category&id_lang=2
to
https://newdomain.com/page1/
http://olddomain.com/index.php?id_category=30&controller=category&id_lang=2
to
https://newdomain.com/page2/
http://olddomain.com/index.php
to
https://newdomain.com
I tried the below code but http://olddomain.com/index.php not going to https://newdomain.com :
RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301,NC]
RewriteCond %{QUERY_STRING} ^id_category=28&controller=category&id_lang=2$
RewriteRule ^index.php$ https://newdomain.com/page1/? [R=301,L]
RewriteCond %{QUERY_STRING} ^id_category=30&controller=category&id_lang=2$
RewriteRule ^index.php$ https://newdomain.com/page2/? [R=301,L]
You need to have specific longer matches first and then have rules to remove index.php or domain redirect:
RewriteEngine On
# specific redirects with index.php as optional match
RewriteCond %{QUERY_STRING} ^id_category=28&controller=category&id_lang=2$ [NC]
RewriteRule ^(index\.php)?$ https://newdomain.com/page1/? [R=301,L,NC]
RewriteCond %{QUERY_STRING} ^id_category=30&controller=category&id_lang=2$ [NC]
RewriteRule ^(index\.php)?$ https://newdomain.com/page2/? [R=301,L,NC]
# remove index.php and redirect to newdmain
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteRule ^(?:index\.php/?)?(.*)$ https://newdomain.com/$1 [L,R=301,NC,NE]
Make sure to clear your browser cache before testing this change.
In case you are taking page's id from id_lang= variable then please try following rules. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Rules to redirect to link: https://newdomain.com/page1/ here.
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteCond %{THE_REQUEST} \s/index\.php\?id_category=28&controller=category&id_lang=(\d+)\s [NC]
RewriteRule ^ https://newdomain.com/page%1/? [NE,R=301,L]
##Rules to redirect https://newdomain.com/ here.
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteCond %{THE_REQUEST} \s/index\.php\s [NC]
RewriteRule ^ https://newdomain.com [NE,R=301,L]
I have a website, www.thesite.com and an alias www.lesite.com
i need a htaccess redirection:
I would like that, when I go to www.thesite.com/fr, it redirects me to www.lesite.com/fr
Likewise, when I go to www.lesite.com/en, I would like it to redirect me to www.thesite.com/en
I have tried different methods but i only succeed to create infinite loops !----
Options +FollowSymlinks
RewriteRule ^fr$ http://dev.mariage.ch/fr/ [L]
RewriteRule ^de$ http://dev.hortzeit.ch/de/ [L]
OR
RewriteCond %{HTTP_HOST} !^dev\.hortzeit\.ch\/de\/
RewriteRule (.*) http://dev.hortzeit.ch/de$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^dev\.mariage\.ch\/fr\/
RewriteRule (.*) http://dev.mariage.ch/fr$1 [R=301,L]
You can't use path as part of RewriteCond for HTTP_HOST
instead of dev.hortzeit.ch/de you must use just host part dev.hortzeit.ch
RewriteEngine On
RewriteCond %{HTTP_HOST} !^dev\.hortzeit\.ch [NC]
RewriteRule ^de(/?.*)$ http://dev.hortzeit.ch/de$1 [R=301,NC,L]
RewriteCond %{HTTP_HOST} !^dev\.mariage\.ch [NC]
RewriteRule ^fr(/?.*)$ http://dev.mariage.ch/fr$1 [R=301,NC,L]
I want redirect:
http://cbpq.luisgustavoventura.com/
AND
http://luisgustavoventura.com/cbpq/
to:
http://cbpq.org.br/
i tried:
RewriteCond %{HTTP_HOST} ^(cbpq\.luisgustavoventura\.com|luisgustavoventura\.com/cbpq)$ [NC]
RewriteRule ^(.*) https://www.cbpq.org.br/$1 [L,R]
but doesn't work.
Please, suggest.
You cannot match /cbpq using %{HTTP_HOST} variable. It is better to keep these as 2 separate rules:
RewriteCond %{HTTP_HOST} ^luisgustavoventura\.com$ [NC]
RewriteRule ^cbpq(/.*)?$ http://www.cbpq.org.br$1 [L,NC,R=302]
RewriteCond %{HTTP_HOST} ^cbpq\.luisgustavoventura\.com$ [NC]
RewriteRule ^(.*)$ http://www.cbpq.org.br/$1 [L,NC,R=302]
Bonjour,
I try to redirect urls of a website
Example :
www.exemple.net/?p=2
to
www.exemple.net/index-2.html
www.exemple.net/?p=35
to
www.exemple.net/index-35.html
etc...
So i add this lines to my .htacess :
RewriteCond %{QUERY_STRING} ^(?)p=(.*)$ [NC]
RewriteRule .* /index-%1.html [L,R=301]
But i'm redirected to http://www.exemple.net/index-2.html?p=2
My .htaccess :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^exemple.net$
RewriteRule ^(.*) http://www.exemple.net/$1 [QSA,L,R=301]
RewriteCond %{QUERY_STRING} ^(?)p=(.*)$ [NC]
RewriteRule .* /index-%1.html [L,R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Can you help me please ?
You need to add a question mark at the end of the destination to discard the query string:
RewriteRule .* /index-%1.html? [L,R=301]
Alternatively, use the QSD flag:
RewriteRule .* /index-%1.html [QSD,L,R=301]
Try :
#Redirecting /?p=2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/\?p=([^&\s]+) [NC]
RewriteRule ^ /index-%1.html? [NE,NC,R,L]
#Redirecting /transfer?p=2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/transfer\?p=([^&\s]+) [NC]
RewriteRule ^ /transfer-%1.html? [NE,NC,R,L]
#Redirecting /blog?p=2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/blog\?p=([^&\s]+) [NC]
RewriteRule ^ /blog-%1.html? [NE,NC,R,L]