Redirect that starts with a? - regex

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]

Related

Redirecting using regular expression in .htacces

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]

How to redirect user to other link only when complete url matches

I want to redirect the user to other link only if the complete url matches and also is it possible that after redirection the url remains same as that of the old one from where user is redirected
I am writing the following rule
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !http://bestcenters.net/services$ [NC]
RewriteRule ^(.*)$ https://4677--586.rocketquotes.com/franchise [L,R=301]
Yes i have solved the issue. You just have to 301 redirect the new rule will looks like this
Redirect 301 ^/old-page.html$ http://newdomain/
This is the rule that helped me achieve what I wanted.

htaccess gives 404 i qualified the page is there

I have a site created specific for mobiles. I added the code below into my htaccess for a redirect but it does not seem to work.
Can anyone enlighten me please
#custom redirects
RewriteEngine on
Redirect 301 /cartypes.php?cartype=12 http://m.cartypecompany.com/redcars.php
#end custom redirects
Redirect directive is not used with mod_rewrite's RewriteEngine On and you need a RewriteCond to match query string. Use this rule:
RewriteEngine on
RewriteCond %{HTTP_HOST} =m.cartypecompany.com
RewriteRule ^redcars\.php$ /cartypes.php?cartype=12 [L,NC,QSA]

How do I redirect this URL via htaccess?

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]

How to remove numbers from the url and redirect with 301

I have lots of user profile url and want remove user id from the url and redirect 301 with .htaccess
For example my current url is http://www.example.com/1084-jerome-smith/profile.php and want redirect this way http://www.example.com/jerome-smith/profile.php
You may try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(.*)/[\d]+-(.*)$ [NC]
RewriteRule .* %1/%2 [R=301,L]
It will redirect permanently:
http://www.example.com/1084-jerome-smith/profile.php
To:
http://www.example.com/jerome-smith/profile.php
Will redirect any URL with this format: http://www.example.com/OptionalFolders/NumericID-anything-anything/anyname.php, where NumericID is the number 1084 to be removed in this case.