I have to redirect urls like
www.site.com/?page=user?id=5
to something like
www.site.com/users/5
I wrote this regular expression
.*\?page=(.*)&id=(.*)
But it doesn't seem to work?
Full redirect rule:
Redirect 302 ^/.*index.php\?page=(.*)&id=(.*) /$1/$2
Redirect directive works on URL path only ie /index.php the part after ? is part of QUERY_STRING and it can not be matched using Redirect, You need to use mod-rewrite
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page=([^&]+)&id=(.+)$ [NC]
RewriteRule ^index\.php$ /%1/%2? [L,R]
Related
I need to redirect URL's with a keyword string used in our AdWords campaign back to my home page using an htaccess rewrite rule. This is what I have already tried...
RewriteRule ^/?keyword=(.*)$ http://{HTTP_HOST}/$1 [R=301]
example:
Looking to make /?keyword=carrots redirect to my home page.
In order to handle redirects involving Query Strings, you will need to use a
RewriteCond %{QUERY_STRING}
in your .htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} (.+)
RewriteRule ^$ http://%{HTTP_HOST}/%1/? [NC,L,R=301]
I would like to redirect all the URLs like this one:
http://example.com/wp-admin/admin-ajax.php?action=flare_get_counts&url=...
to
http://example.com
How do I do that with a .htaccess redirect so that ALL the URLs with anything after "&url=" get automatically redirected?
You can do it like this:
RewriteEngine On
RewriteCond %{QUERY_STRING} action=flare_get_counts&url=.+
RewriteRule wp-admin/admin-ajax.php /? [R=302,L]
You can remove the 302 if the rule works, that will make the redirect permanent.
If you wanted to redirect any URL that has a query string containing url=..., change the last line to
RewriteRule ^ / [R=302,L]
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]
how to redirect this page:
example.com/index.php?option=1&view=news
to this
/news
I'm tying simple
Redirect /index.php?option=1&view=news /news
but it's not working
You need to use mod_rewrite to match query string:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php\?option=1&view=news [NC]
RewriteRule ^ /news? [R=301,L]
I need to have a redirect done to a site I have that is a 404 error.
Redirects are done in a .htaccess file for Joomla. This is what I have currently:
redirect 301 /?view=category&id=12:bestfriend&Itemid=946&start=20 http://www.mysite.com
But it doesn't redirect because it starts with a "?".
Any ideas? I have a number amount of these like this - not just one.
You cannot match query string using Redirect directive. Use mod_rewrite like this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^view=category&id=12:bestfriend&Itemid=946&start=20 [NC]
RewriteRule ^ http://www.mysite.com/? [R=301,L]