htaccess 301 redirect query to new domain - .htaccess

trying to redirect this query to a new domain:
www.domain.com/search.php?q=keyword
to
www.newdomain.com/search.php?q=keyword
keyword can be any word
And want to keep the rest in domain, I just need to redirect this query.
I try several ways and the one I found closer to solution is this one:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^q=1$
RewriteRule ^search\.php$ http://www.newdomain.com/search.php?q=$1 [R=301,L]
but does not work!
Hope someone could help me correcting this and also if this is the best way to do the job?
Many thanks.

You're pretty close.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^q=.+ [NC]
RewriteRule ^(search\.php)$ http://www.newdomain.com/$1 [R=301,L,NC]

Try this
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=123$
RewriteRule ^/?product\.php$ http://website.com.au/product_123.php? [L,R=301]
Or
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([^&]+)
RewriteRule ^/?product\.php$ http://website.com.au/product_%1.php? [L,R=301]

this works and is simple
RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.com/$1 [QSA]

Related

removing url parameters from one url using .htaccess codes

I tried lot of combinations using available examples (.htaccess directives), but I couldn't able to achieve what I want. The problem is...
My actual URL is
http://localhost/smon2/custsms/index.php?p_mob=9886419001
What I want is
http://localhost/smon2/custsms/
Please help me in wrinting .htaccess code lines.
Thanks
I tried with few of the items below...
RewriteEngine On
RewriteCond %{QUERY_STRING} ^p_mob=1$
RewriteRule (.*) $1? [R=permanent]
RewriteEngine On
RewriteCond %{QUERY_STRING} "p_mob=" [NC]
RewriteRule (.*) /$1? [R=301,L]
RewriteEngine On
RewriteRule ^/custsms/%{QUERY_STRING}/?$ http : //localhost/smon2/custsms/ [NC,L]
Nothing was working. please help.
Replace all your current rules with this rule:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /smon2/
RewriteCond %{QUERY_STRING} ^p_mob=\d+ [NC]
RewriteRule ^(custsms)/index\.php$ $1/? [R=301,L,NC]

Redirect URL to external URL

I want to be able to redirect this URL:
www.shorturl.co.uk/answers
To this URL:
http://actual.url.co.uk/answers.html
I have tried the following in .htaccess but it doesn't appear to be working:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.shorturl\.co.uk$ [NC]
RewriteRule ^answers$ http://actual.url.co.uk/answers.html [L,R=301,NC]
Can anyone point out where I might be going wrong? Thanks
I'm not an expert in this, but you could give it a try:
RewriteCond %{HTTP_HOST} ^www\.shorturl\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^shorturl\.co\.uk$
RewriteRule ^answers$ http://actual.url.co.uk/answers.html [R=301,L]

Redirect one domain to another in .htaccess

I am looking to one domain to another with all sub-urls as well. The original url would be ehanceinsdev.com and the redirected url would be www.enhanceinsurance.com. I would want it so that enhanceinsdev.com/foo would go to www.enhanceinsurance.com/foo.
Thanks for your help!
You can use this simple rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^enhanceinsdev\.wpengine\.com$ [NC]
RewriteRule ^ http://www.enhanceinsurance.com%{REQUEST_URI} [R=301,L,NE]
Try
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^ehanceinsdev\.com$ [NC]
RewriteRule ^(.*)$ http://www.enhanceinsurance.com/$1 [R=301,L]

Issue with subdomains and htaccess for SEO

I would like to change urls from:
http://subdomain.domain.com/page/ to http://subdomain.domain.com/?page=pagename
and also:
http://domain.com/page/ to http://domain.com/?page=pagename
though haven't had much success.
Here is my htaccess file so far [updated]
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Remove 'www'
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Add slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://resolutiongaming.com/$1/ [L,R=301]
# Subdomain redirect
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1
I used RewriteRule ^([a-zA-Z]+)/$ ?page=$1 which seemed to work for the domain url but not the subdomain. Any help would be appreciated.
Actually had to do something like this recently. Try this for your Subdomain redirect block:
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$2 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$2 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$2 [R=301,L]
Or maybe this; note the change from $2 to $1:
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
EDIT: Or Maybe try this. Note that you need to capture two parts of the URL to rewrite as you are explaining. Each item in parenthesis ( and ) corresponds to a string in the rewrite. Try this. Using your nicer regular expression RewriteRule as you mention in the comments:
RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/$2 [R=301,L]
Or maybe this:
RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/page=$2 [R=301,L]
So it was an easy fix really. I basically put a .htaccess file in each subdomain directory that looks like this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1
Hope this helps someone. :D

redirect one domain to another with htaccess rules

I was wondering how i can redirect my users from my old domain to a new url
forexample
http://www.5.joblessbuddy.com/news.html
into this
http://www.1.joblessbuddy.hu/news.html
i did this on my htaccess but not working
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} http://www.5.joblessbuddy.com/$ [NC]
RewriteRule ^(.*)$ http://www.1.joblessbuddy.hu$1 [R=301,L]
any suggestion would be appreciated
thanks in advance
Try this:
RewriteCond %{HTTP_HOST} (www\.)?5\.joblessbuddy\.com [NC]
RewriteRule ^(.*)$ http://www.1.joblessbuddy.hu/$1 [R=301,L]
btw: mod_rewrite cheat sheet v2 is your friend.

Resources