Redirect query url to new page - .htaccess

I have this url
www.example.com/nothing_here?registration=disabled
and I want to redirect it to
www.example.com/errors/418.php
I cannot get rid of the nothing_here part of the url. How to do this?
Thanks

In the htaccess file in your document root, add:
RedirectMatch 301 ^/nothing_here$ /errors/418.php?
or using mod_rewrite:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^registration=disabled$ [NC]
RewriteRule ^nothing_here$ /errors/418.php [L,R=301]

Related

How to force redirect query string URL with htaccess?

I want to redirect example.com/recipes/signup?code=OLD277 to example.com/recipes-user/register How can I achieve it via htacces?
I tried the below code in .htaccess but its not working!
Redirect /recipes/signup?code=OLD277 http://example.com/recipes-user/register
You may use this rule as your topmost rule in site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /recipes/signup\?code=OLD277\s [NC]
RewriteRule . /recipes-user/register? [R=301,L,NE]

Replace word within url and redirect

I am trying to replace word with another word in url and redirect but its not wokring due to query string.
Here is eg. Here is the url and i want to redirect it
https://www.custesitetest.com/test_calculator.php?tf=to&loc=staines
to
https://www.custesitetest.com/autoqoute?tf=to&loc=staines
RedirectMatch ^/test_calculator.php/(.*)$ https://www.custesitetest.com/autoquote/$1
You can use this rule in your root .htaccess:
RedirectMatch 301 ^/test_calculator.php?$ /autoquote
Try it like this with mod_rewrite,
RewriteEngine On
RewriteCond %{REQUEST_URI} ^test_calculator.php
RewriteCond %{QUERY_STRING} ^(.+)
RewriteRule ^ autoquote?%1 [R=301,L]

htaccess 301 redirect to index page

I need the sloution for home page 301 redirection.
If I enter http://www.starmed.dk/index.php in the browse bar, then it will be redirected to http://www.starmed.dk without index.php
Any idea how to do this with an HTACCESS 301 redirect?
Thanks in advance.
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^starmed.dk[nc]
RewriteRule ^(.*)$ http://www.starmed.dk/$1 [r=301,nc]
//301 Redirect Old File
Redirect 301 www.starmed.dk/index.php www.starmed.dk
Edit:
Perhaps your configuration is different. perhaps this:
RewriteRule ^www.starmed.dk/index.php$ www.starmed.dk/ [R=301]
Try the following :
DirectoryIndexRedirect Off
RewriteEngine on
RewriteRule ^index\.php$ / [L,R]

301 from mobile=N in htaccess

I wanted to make a 301 from URL with ?mobile=N parameter to URL without that parameter. Google is indexing this URL and I think that 301 is the best way to fix that
eg.
FROM
www.example.com/?mobile=N
TO
www.example.com
FROM
www.example.com/example/example.com?mobile=N
TO
www.example.com/example/example.com
You can use in your .htaccess:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^mobile=N$ [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L]

301 Redirect with query string and anchor

I have the following URL:
http://www.current-domain.com/register?tabs=2#tabs
I need this to redirect to another URL on a new domain
http://www.new-domain.com/register#register-form
I have looked into 301 redirects and tried the following:
Redirect 301 /register?tabs=2#tabs http://www.new-domain.com/register#register-form
The problem is, when I hit the current URL, the new URL is:
http://www.new-domain.com/register#register-form?tabs=4 which is incorrect
Any help is much appreciated
Thanks
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?current-domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^tabs=2$ [NC]
RewriteRule ^register/?$ http://www.new-domain.com/register#register-form [L,NC,R=301,NE]

Resources