I am trying to redirect a page A with query string, pageA?queryString to pageB. But while redirecting, pageB should be internally redirected. It should pass through and in URL it should show pageA but internally should show the content of page B
Already tried with:
Case1:
RewriteCond %{QUERY_STRING} ^hideChrome$
RewriteRule (.*)/pageA(/*)$ $1/pageB/ [PT,L]
Output:
Error is thrown: pageB is not found
Case 2:
RewriteCond %{QUERY_STRING} ^hideChrome$
RewriteRule (.*)/attribution(/*)$ $1/attribution1/ [L,R]
It is redirected to 'pageB' and URL is also displaying as 'pageB'
Try
RewriteCond %{QUERY_STRING} ^hideChrome$
RewriteRule (.*)/pageA(/*)$ $1/pageB/ [PT,L,QSA]
https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_qsa
Related
How to redirect
/index.php?route=blog/blog to /blog
and
index.php?route=information/contact to /contact
The site is on Opencart 2.3.
I tried with:
RewriteRule ^index.php?route=blog/blog$ /blog [R=301,L]
I've come to the point where pages open in both ways, but don't redirect.
You can't match against query string (anything that goes after ? in URL) in pattern of a RewriteRule . You need to match against %{QUERY_STRING} variable using a RewriteCond directive
RewriteEngine On
RewriteCond %{QUERY_STRING} ^route=[^/]+/(.+)$ [NC]
RewriteRule ^ /%1? [L,R=301]
I have a URL :
https://www.example.com/login/login.cgi?user=option
Want to exactly match login.cgi
If user hits https://www.example.com/login/login.cgi need to redirect to external site say www.redirect.com
If anyone hits https://www.example.com/login/login.cgi?user=option it should not cause any redirection.
I tried various option of query string and as well Rewrite rules seems to not work.
I tried using :
RewriteEngine On
RewriteCond %{QUERY_STRING} ^login.cgi$
RewriteRule ^login/$ https://www.redirect.com? [R=302,L]
This should work for you.
RewriteEngine on
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?login/login\.cgi$ https://example.com [R,L]
This will redirect yoursite.com/login/login.cgi to example.com .
The condition RewriteCond %{QUERY_STRING} ^$ matches empty querystring meaning that when the the URI is /login/login.cgi without any querystring the Rewriterule will be applied.
The /? in the beginning of RewriteRule pattern makes it possible to use the rule in both contexts server.config or in htaccess.
I'm migrating to a new website.
I want to be able to redirect everything from the old website to the new website in the following structure.
Example 1:
http://dev.website-old.com/abc/123
to
http://dev.website-new.com/abc/123
Example 2:
http://dev.website-old.com/abc/123/xyz
to
http://dev.website-new.com/abc/123/xyz
How do I accomplish this?
This rewrite redirect all requests (1:1) from dev.website-old.com to dev.website-new.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?dev\.website-old\.com [NC]
RewriteRule (.*) http://dev.website-new.com/$1 [R=301,L]
I redirect the news with the folling code in htaccess:
RewriteCond %{REQUEST_URI} news-detail\.html
RewriteCond %{QUERY_STRING} L=0 [NC]
RewriteCond %{QUERY_STRING} (tx_news_pi1\[news\]=101|tx_news_pi1%5Bnews%5D=101) [NC]
RewriteRule ^.*$ http://example.net/news/news-detail/8/2016/newstitle? [R=301,L]
The redirect works. Is it possible to use the parameter from QUERY_STRING in RewriteRule? So that every news article is automatically redirected to speaking url. I tried to use some of the parameters from config file but it doesn't work.
You don't get the news title in htacces by the id uid only.
I propose to leave url like they are, use realurl and set a canonical url to the realurl variant
I want to 301 redirect some URLs which contain "option=com_virtuemart".
I tried with this code:
RewriteCond %{QUERY_STRING} ^option=com_virtuemart
RewriteRule ^(.*)$ http://www.newsite.com/$1 [L,R=301]
But it doesn't work.
The code is working, but the server is disabled htaccess controll..