I have URLs like
/?test that I want to rewrite to /page.php?page=test
I tried like this but for some reason it doesn't work.
RewriteRule ^\?([a-z0-9\-\+]{3,20})/?$ /page.php?page=$1 [NC,QSA]
What am I doing wrong?
The query string can only be tested with the RewriteCond directive. The RewriteRule pattern is only tested against the URL path (in .htaccess files the URL path without the per-directory prefix).
So try this:
RewriteCond %{QUERY_STRING} ^[a-z0-9-+]{3,20}$ [NC]
RewriteRule ^$ /page.php?page=%0 [QSA]
Related
I want to rewrite an URL like this
http://domain1.com/some_directory/12345678?x=1/audio.mp3
to an URL like this http://domain2.com/12345678?x=1.
I tried this rewrite rule RewriteRule /some_directory/(.*)$/(.*).mp3 http://domain2.com/$1 [NC,L] but it doesn't work.
You can use this rule in root .htaccess by matching query string in a RewriteCond:
RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)(x=\d+)[^.]+\.mp3 [NC]
RewriteRule ^some_directory/(.*)$ http://domain2.com/$1?%1 [NC,L,R=302,NE]
I have the following example urls that i need redirecting to www.example.co.uk
http://www.example.co.uk/wordpress/?feed=comments-rss2
http://www.example.co.uk/wordpress/?feed=rss2
http://www.example.co.uk/wordpress/?cat=518
http://www.example.co.uk/wordpress/?cat=514
http://www.example.co.uk/wordpress/?cat=520
http://www.example.co.uk/wordpress/?cat=521
http://www.example.co.uk/wordpress/?cat=523
http://www.example.co.uk/wordpress/?cat=515
http://www.example.co.uk/wordpress/?p=119
There are many more urls further to this list that all have a wordpress/ notation.
Would I have to write a conditional rewrite for each like this:
RewriteCond %{QUERY_STRING} ^feed=comments-rss2$
RewriteRule ^/wordpress/?(.*)$ http://www.example.co.uk [R=301,L]
RewriteCond %{QUERY_STRING} ^cat=518$
RewriteRule ^/wordpress/?(.*)$ http://www.example.co.uk [R=301,L]
or is there a rule i can write that redirect all urls that have /wordpress in them to redirect to www.example.co.uk
I believe a single rule like would be suffice:
RewriteCond %{QUERY_STRING} (^|&)(feed|p|cat)=[^&]+ [NC]
RewriteRule ^wordpress(/.*)?$ http://www.example.co.uk/? [R=301,L,NC]
Make sure this is very first rule in your .htaccess just below RewriteEngine On line.
I want to redirect at .htaccess every URL that has inside it a "?" character to the root of my site (domain.com).
I have read this :
301-htaccess-redirect-with-special-characters
/how-to-make-htaccess-rule-for-a-url-with-specific-characters
But I still do not know how to do it. I know only a bit of regular expresions.
Examples Urls I would like redirect to the root of my site :
http://www.portaltarot.com/index.html?url=/MHL-Papus.html
http://www.portaltarot.com/index.phpindex.php?Itemid=249
You need to use mod_rewrite to do this, so something like:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^url=/MHL-Papus.html$
RewriteRule ^index\.html$ / [L,R=301]
RewriteCond %{QUERY_STRING} ^Itemid=249$
RewriteRule ^index\.phpindex\.php$ / [L,R=301]
I have a site that has a bunch of URLs indexed in Google that look like this -
http://www.domain-namr.com/?option=filter&option2=&option3=
I am trying to redirect all of these to a new URL in HTACCESS with this code -
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^option=filter$
RewriteRule ^(.*)$ /new-url.html [R=301,L]
Of course it is not working. On all of the pages that have a filename I can use in the request uri condition, the redirects work. What am I missing?
It is not working due to the wrong regex pattern in your rule.
Try this rule as your very first rule in root .htaccess:
RewriteCond %{QUERY_STRING} ^option=filter(&|$) [NC]
RewriteRule ^$ /new-url.html? [R=301,L]
I am basically just trying to write a .htaccess redirect that turns the url
www.example.com/Artist/Profile?Artist='test' to www.example.com/Artist/test
without actualy redirecting the user.
use the following directive
RewriteCond %{QUERY_STRING} (^|&)artist='([^&]+)' [NC]
RewriteRule ^Artist/Profile$ /Artist/%2? [L,NC]