Been trying to figure this one out - also found similar examples here on stack overflow, but can't get it to work.
I'm trying to rewrite a URL from
http://www.domain.com/index.php?option=com_users&view=login&return=aHR0cDovL3d3dy5vc
to:
http://www.domain.com/login&return=aHR0cDovL3d3dy5vc
I've tried this:
RewriteRule ^/?index.php?option=com_users&view=login&return(.*)$ /login?return$1 [R=301,L]
But as I said, can't get it to work, so appreciate any help.
Thanks!
You can use this rule as first rule in your .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php\?option=com_users&view=([^&\s]+)&return=([^&\s]+)
RewriteRule ^ /%1?return=%2 [R=301,L]
You cannot match QUERY_STRING using RewriteRule.
Related
I would like to make a rewrite rule for my website but I cannot seem to get the proper code in order to make this work.
The current URL of my website is looking like http://www.mohanadarafe.io/JSON/json.html
I want it to be: http://www.mohanadarafe.io/json
I have tried the following code but it does not seem to work:
RewriteEngine On
RewriteRule ^\.html$ /json [L]
Any idea how to fix this?
You have it reversed. Have it like this:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /JSON/json\.html [NC]
RewriteRule ^ /json [R=301,L]
# internal forward from pretty URL to actual one
RewriteRule ^json/?$ JSON/json.html [L,NC]
Then you can have your URL as: http://www.mohanadarafe.io/json
I have a 404 page being found by analytics. I'm having trouble figuring out the correct syntax for redirecting the link below via .htaccess. Can anyone offer a solution? Thank you very much.
http://www.mywebsite.com/product-categories?format=feed&type=atom
I tried this and plenty of others without success.
RewriteCond %{QUERY_STRING} ^format=feed&type=atom$
RewriteRule ^product-categories/$ http://www.mywebsite.com/product-categories/? [L,R=301]
You have condition reverse in your RewriteRule. Use this rule:
RewriteCond %{QUERY_STRING} ^format=feed&type=atom$ [NC]
RewriteRule ^product-categories/?$ /product-categories/? [NC,NE,L,R=301]
can someone tell me how to write rewrite rule: I have many links that look like:
http://www.mavrica.com/index.php?eID=tx_cms_showpic&file=uploads%252Fpics%252Fmozic_05.jpg&width=800m&height=600m&bodyTag=%253Cbody%2520bgcolor%253D%2522black%2522%253E&wrap=%253Ca%2520href%253D%2522javascript%253Aclose()%253B%2522%253E%2520%257C%2520%253C%252Fa%253E&md5=025892981ebd7f312b96276beb3ee194
I would like to redirect all of them to http://www.mavrica.com/fotogalerije/
All the links have in common first part (up to tx_cms_showpic).
I tried the following htaccess rules:
RewriteRule /index.php?eID=tx_cms_showpic$ http://mavrica.com/fotogalerije/ [R=301]
and with
RedirectMatch 301 ^/index.php?eID=tx_cms_showpic(.*) http://www.mavrica.com/fotogalerije/
but none of them work.
What have I missed out?
Thanks for help!
You need to use %{QUERY_STRING} to capture and/or match the query string part of the URL:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?eID=tx_cms_showpic [NC]
RewriteRule ^ http://mavrica.com/fotogalerije/? [R=301,L]
I'm trying to set up a rewrite that will redirect this URL:
/video-2011.php?video=150
to this:
/video/150/freeform-title-text-here/
I have the rewrite working using this line in my HTACCESS:
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [L]
But as soon I add R=301 into the mix, it breaks. Any ideas?
Here's the full HTACCESS when it breaks:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [R=301,L]
Any help is greatly appreciated, thanks!
I think you might be missing a line from your .Htaccess.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^video/([0-9]+)/([a-z0-9-_]+)$ video-2011.php?video=$1 [L]
#New
RewriteCond %{REQUEST_URI} !^/video/([0-9]+)/([a-z0-9-_]+)/?$
RewriteCond %{QUERY_STRING} ^video=([0-9]+)&name=([a-z0-9-_]+)/?$
RewriteRule ^video-2011.php$ video/%1/%2/? [R=301,L]
I assuming you want to rewrite the url if it is:
/video/150/freeform-title-text-here/
And redirect the url if it is:
/video-2011.php?video=150
to:
/video/150/freeform-title-text-here/
So this way it keeps the urls looking pretty and tidy.
Please correct me if I am wrong.
Edit
I've added in a RewriteCond to stop the second rewrite happening.
As the first rule will obviously rewrite:
/video/150/freeform-title-text-here/
Which means the query string you don't see:
/video-2011.php?video=150
Would of made the second rule happen too.
Can you try:
RewriteRule ^video/([0-9]+)/ /video-2011.php?video=$1 [R=301,L,NC,QSA]
And yes it will redirect /video/150/foo to /video.php?video=150 not the other way around as you've stated in your question.
I know there are a lot of similar questions, but couldn't find a value in them.
I am doing the following redirect in .htaccess
RewriteCond %{REQUEST_URI} ^/old/url/(.*)$
RewriteRule ^ /new-url/$1 [L,R=301]
The final result I would like to get is http://old/url/page/2 --> http://new-url/page/2
but I am getting getting wrong urls, like http://new-url/old/url/page/2
could someone give me a hint how to include only /page/2/ part appended in the final url redirect
thanks
Try:
RewriteCond %{REQUEST_FILENAME} ^/old/url/(.*)$
RewriteRule ^ /new-url/$1 [L,R=301]