So I've to make some 301 redirection on a website,
I've this url :
file.aspx?level1=Navigation+Pilot
I want to redirect this url to this final one :
/list_pilots/navigation_pilot/
So I wrote this rule :
RewriteRule ^file.aspx?level1=Navigation+Pilot /list_pilots/navigation_pilot/ [R=301,L,QSD]
But the final url when I test into my browser is :
http://www.test.com/list_pilots/navigation_pilot/?level1=Navigation+Pilot
How to get rid of the parameters in this url ?
Thanks for your help !
QueryString is not part of match in RewriteRule's pattern. To match against querystring, you need to use a RewriteCond.
RewriteEngine on
RewriteCond %{THE_REQUEST} /file\.aspx\?lavel1=([^\s+]+)\+([^\s]+) [NC]
RewriteRule ^ /list_pilots/%1_%2? [L,R]
Related
I want to replace get parameter with mod_rewrite in .htaccess. I have Url www.domain.at/success?id=12345 and need to replace "id" with "vid" -> www.domain.at/success?vid=12345
This replacement must only work on "success" page/uri, but not on other pages of website.
I tried
RewriteEngine On
RewriteRule ^(.*)success?id=([^0-9]*)$ /$1success?vid=$2 [R=301,L]
But this is not working on dynamic part?
Thanks for help!
Martin
You have to match query parameters in RewriteCond separately from request URI like this:
RewriteCond %{QUERY_STRING} ^id=(.+)$ [NC]
RewriteRule ^success/?$ /$0?vid=%1 [R=301,L,NC]
Hi all I need to redirect based on query string though htaccess in Apache.
I want that all the queries that contain jjj redirect to my homepage
I used the code below but its not working could you please help me¿
Thanks in advance,
Mauri
RewriteCond %{QUERY_STRING} ^jjj$
RewriteRule (.*) http://www.eventosbarcelona.com [R=301,L]
Your rule redirects example.com/?jjj to example.com/?jjj I guess, You are getting redirect loop error as both urls are same. By default, mod-rewrite appends old query strings to the destination url. You need to use a ? at the end of the Rewrite destination url to discard query string.
Try this :
RewriteEngine on
RewriteCond %{QUERY_STRING} ^jjj$
RewriteRule (.*) http://example.com? [L,R]
This will redirect /?jjj to http://example.com/ .
I need a rewrite for htaccess that will take this sample url and rewrite it to the homepage and get rid of the query string.
Example:
Rewrite this:
http://www.domain.com/e-newsletters/forward/49.html?key=BkPOBo4l&tmpl=component
to this:
http://www.domain.com/
Here are the "variables" in the url:
49.html there could be any number.html
?key=BkPOBo4l - the string "BkPOBo4l" will change
&tmpl=component will not change
Any help would be greatly appreciated.
To redirect
http://www.domain.com/e-newsletters/forward/49.html?key=BkPOBo4l&tmpl=component
to http://www.domain.com/
You can use the following :
RewriteEngine on
RewriteCond %{THE_REQUEST} /e-newsletters/forward/[0-9]+\.html\?key=.+&tmpl=component [NC]
RewriteRule ^ http://www.domain.com/? [L,R]
I've tried using each of the following
Redirect 301 /example http://website.com/new-page
RedirectMatch 301 /example(.*) /new-page/$1
RewriteRule ^example/(.*)$ http://website.com/new-page$1 [R=301,L]
In each case the final URL resolves to "website.com//new-page//?q=/example/"
Note that it is adding /?q=/example/ to the final URL.
That might be due to other rules in your .htaccess. Use this rule to capture original string from THE_REQUEST variable. And add ? in the end to strip off query string.
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+example(\S*)\s [NC[
RewriteRule ^ http://website.com/new-page/%1? [R=301,L,NE]
I want to redirect the url http://www.mywebsite.com/tutos/tutos.php?q=my-tuto/tuto-1.html to
http://www.mywebsite.com/tutos/tutos/my-tuto/tuto-1.html, how to do that with a .htaccess ?
I tried this, but it's don't working... :
RewriteRule ^http://www.mywebsite.com/tutos/([^-]*)$ http://www.mywebsite.com/tutos/tutos.php?q=$1 [L,QSA]
Thanks !
The rule that you have seems to be doing the opposite of what you say that you want. It's redirecting the non-query-string URL to the query-string URL. But if that's what you want, you need to remove the host and protocol from the regular expression. Only the URI (sans query string) is used to match against in a RewriteRule:
RewriteRule ^tutos/([^-]*)$ /tutos/tutos.php?q=$1 [L,QSA,R=301]
But if you wanted it the other way around like you had asked:
RewriteCond %{QUERY_STRING} (.*)(^|&)q=([^&]+)(.*)
RewriteRule ^tutos/tutos.php$ /tutos/%2?%1%3 [L,R=301]