I'm looking for some help. I wanted to redirect the following paramters to another url, how can I make this possible? I have googled alot of other solutions but I fail to make this one work.
https://(www).website.com/reservation#!/confirm?code=a1XapXsCmlaC0
to
https://new-website.com/test/page#!/confirm?code=a1XapXsCmlaC0
Attempted code:
RewriteRule \/reservation#!\/confirm\?code=$ https://test.com/$1
"grep"-ing the code value would make it much easier.
Any help is much appreciated.
Thanks in advance
You may use this redirect rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?website\.com$ [NC]
RewriteRule ^reservation/?$ https://test.com/test/page [L,NC,R=301]
Query string and fragment i.e. part after # will automatically be forwarded to the new URL.
Based on your shown samples, could you please try following. Where you want to redirect from (www).website.com to new-website.com in url.
Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*) [NC]
RewriteRule ^ https://new-%1/test/page#!%{REQUEST_URI} [QSA,NE,R=301,L]
Related
I want to redirect request to sample.php if pattern was like below
sample.com/vacation
I tried this code but not work correctly, redirect all request contain vacation such as sample.com/anything/vacation
RewriteCond %{REQUEST_URI} /vacation
RewriteRule ^ /sample.php [L,R]
how can I achieve that ?
With your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^vacation/?$ sample.php [NC,L]
Im trying to make an apache(2) RewriteRule which is using a QUERY_STRING to redirect a user to a friendly to read URL, but it is causing a redirect loop.
What I want to achieve is that when a user requests for the index.php?layout=751&artnr=# URL, that this request gets redirected to /another/page/#.
And in a way the Redirect works, but Apache keeps redirecting the user once it has reached the /another/page page
The RewriteRule looks like this:
RewriteCond %{REQUEST_URI} ^/index.php
RewriteCond %{QUERY_STRING} ^layout=751&artnr=(.+)$
RewriteRule ^index\.php$ another/page/%1? [R=301,L]
I've been searching alot of issues about this situation but none of them really have the answer that solves my problem, since those problems don't use a QUERY_STRING.
I have also tried to add the RewriteOptions maxredirects=1 option, but this doesn't solve the problem either.
Any help would be appreciated.
Thanks in advance.
Use THE_REQUEST variable instead of REQUEST_URI like this:
RewriteCond %{THE_REQUEST} /index\.php\?layout=751&artnr=([^\s&]*) [NC]
RewriteRule ^ another/page/%1? [R=301,L,NE]
THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules.
This assumes a RewriteBase has been set above this rule.
Clear your browser cache or use a new browser to test this change.
I'm trying to perform the following permanent redirections in .htaccess file, but I can not make them work. Can you help me?
Thank you very much. Regards!
Redirects are these:
http://www.mapfre.com.pa/productos/#39 to https://www.mapfre.com.pa/seguros-pa/seguros/seguros-salud/
http://www.mapfre.com.pa/productos#36 to https://www.mapfre.com.pa/seguros-pa/seguros/seguros-auto/
http://www.mapfre.com.pa/?post_type=corporativo&p=21 to https://www.mapfre.com.pa/seguros-pa/sobre-mapfre-panama/historia/
There's no way to make server-side redirect for URLs with an anchor #.
The last one may be done by this rule:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^post_type=corporativo&p=21$
RewriteRule ^$ /seguros-pa/sobre-mapfre-panama/historia/ [R=301,L]
We are trying to redirect everything from one domain to another with the following
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule .? http://www.example2.com%{REQUEST_URI} [R=301,L]
When we visit http://www.example.com/v2sc
We are being redirected to http://www.example2.comv2sc
We would like to be redirected to http://www.example2.com/v2sc considering www.example2.comv2sc is not a valid hostname
Any ideas on how we can accomplish this?
Thank you!
It seems like you're using a .htaccess file for this. In that context the leading slash is not present in %{REQUEST_URI} so it's up to you to put it back in.
RewriteEngine On
RewriteCond %{HTTP_HOST} !=www.example.com
RewriteRule ^ http://www.example2.com/%{REQUEST_URI} [R=301]
Please also note that solutions like this should be used only if you cannot edit the main server configuration file. Doing so would allow you to use a cleaner combination of vhosts and Redirect directives that would run much more quickly.
Would greatly appreciate it if someone could help me make this work.
I'm trying to make domain.com/painting.php?name=hello redirect to domain.com/page/hello while keeping my rewrite :
RewriteCond %{QUERY_STRING} name=([^&]+)
RewriteRule ^painting\.php$ /page/%1? [R=301,L] #redirects to page
RewriteRule ^page/([^/\.]+)/?$ painting.php?name=$1 [L] #rewrites painting
I would like to keep only the "pretty url". Please help.
Found answer here: simple 301 redirect with variable not working, why?
I'm assuming what you actually want to do is be able to accept the URL domain.com/page/hello and rewrite it (invisibly) to domain.com/painting.php?name=hello. If so, try this
RewriteRule ^page/([^/.])+/?$ painting.php?name=$1 [QSA,L]