htaccess redirect including string - .htaccess

I know how to redirect normal links without strings, but including the string for email addresses has me stuck. Can someone please assist with 301 redirecting a URL to another domain including the URL string? I need to redirect the following:
www.domain.com/page.php?e=tom-jones#mail.com
to
www.domain1.com/?e=tom-jones#mail.com
I just need to keep the email address in the string when it's redirected to the new URL
Thanks in advance.

In the htaccess file in your www.domain.com document root, you can just add:
RedirectMatch 301 ^/page\.php$ http://www.domaon1.com/
The query string will automatically get appended. Or you can use mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^page\.php$ http://www.domaon1.com/ [L,R=301]

Related

htaccess redirect url by adding parameters

Need Guidance of 301 redirecting Url through htaccess matching specific format
Existing URL
http://www.example.com/index.php?option=com_toys&limitstart=20
Proposed URL
http://www.example.com/index.php?option=com_toys&view=list&Itemid=2&limitstart=20
Here limitstart may change to 0,20,40,60 to even 1000 and thus should remain same in the new proposed url too
Can anyone advise on to redirect using htaccess of above
You need to match query string using RewriteCond using a regex to capture both parameters:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(option=com_toys)&(limitstart=\d+)$ [NC]
RewriteRule ^/?index\.php$ %{REQUEST_URI}?%1&view=list&Itemid=2&%2 [L,NC,R=301]

.htaccess help! redirecting URL with query string to root

I'm new to htaccess so please bear with me..
I'm trying to redirect traffic to URLs with query string to the root of my site as these URLs are no longer used.
Here is an example:
I would like traffic to this URL
https://www.DomainName.com/subdir1/subdir2/cond_e.asp?obark=110246
to go to http://www.DomainName.com
I do not need to keep the URL or anything just redirect to my homepage.
I need to do this for query string value from obark=110246 all the way up to obark=120000.
I've basically played around with the below to get at least one URL to redirect properly but never could get it to work at all.
RewriteCond %{QUERY_STRING} ^oPark=110246$
RewriteRule ^subdir1/subdir2/cond_e(.*) ^$? [NE, R=301, L]
What am I doing wrong? please help!
Try with below rule in subdir2,
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/cond_e.asp
RewriteCond %{QUERY_STRING} ^obark=[1]{1}[1-2]{1}[0]{1}[02-9]{1}[094-5]{1}[06-9]{1}
RewriteRule ^ http://www.DomainName.com? [R=301,L]

Redirect only one URL with parameter

I need to redirect URL, for example:
www.mydomain.com/category/sub-category/product?page=shop.ask&flypage=flypage.tpl&product_id=181&category_id=34
To:
www.mydomain.com/category/sub-category/good-product.html
I have a multiple URLs with parameters that need to be redirected to only one or couple of URLs, can you help me, I used Google for hours.
I was try this code at .htaccess:
redirect 301 /category/sub-category/product?page=shop.ask&flypage=flypage.tpl&product_id=181&category_id=34 www.mydomain.com/category/sub-category/good-product.html
But it doesn't work.
You can't match against the query string in a Redirect directive. You'll need to use mod_rewrite:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page=shop.ask&flypage=flypage.tpl&product_id=181&category_id=34$
RewriteRule ^category/sub-category/product$ /category/sub-category/good-product.html? [L,R=301]

Redirect URL with wildcard variables

I am trying to use the htaccess file to redirect a url with random url variables for example:
somesite/news/training-viewdoc.htm?file=somethingrandom
to
somesite-two/news/training-viewdoc.htm?file=that variable
Any clues as to how to do this. Right now I have....
RedirectMatch 301 /news/training-viewdoc.htm?file=(.*) somesite-two/news/training-viewdoc.htm?file=$1
You can't match against the query string in a RedirectMatch, however, it should automatically be appended so you don't need to worry about it:
Redirect 301 /news/training-viewdoc.htm somesite-two/news/training-viewdoc.htm
If you need to only redirect when there's a file in the query string, then you have to use mod_rewrite:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^file=.
RewriteRule ^news/training-viewdoc.htm$ somesite-two/news/training-viewdoc.htm [L,R=301]

htaccess 301 Redirection based on the query string for urls

I've a live url some thing like this,
http://example.com/today.php?year=2012&date=24&mon=07
and i want it to redirected to
http://example.com/holiday-today/year/mon/date
I tried with %{QUERY_STRING} but i dont know how to get three query parameters and pass them to the redirected url.
How can i do this using htacess?
Try adding this in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /today\.php\?year=([0-9]+)&date=([0-9]+)&mon=([0-9]+)
RewriteRule ^today\.php$ /holiday-today/%1/%2/%3? [R=301]
I would reference these similar questions with great answers:
Query string redirection with htaccess
301 redirect from URL with query string to new domain with different query string

Resources