I have found help regarding this in other questions and answers but they do not specifically address what I am trying to do.
My RewriteRules look like this...
#Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.com$[OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*)$ http://newdomain.com/rd/r.php? [QSA]
I need http://domain.com/query.php?sid=1234&pub=123456&c1=will&c2=test1&c3=12345 to redirect to http://newdomain.com/rd/r.php?sid=1234&pub=123456&c1=will&c2=test1&c3=12345
many thanks for any help.
#Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteCond %{HTTP_HOST} ^(www\.)?allsystemsarego.info$
RewriteRule ^(.*)$ http://affiliate.gwmtracker.com/rd/r.php?%1 [R,L]
The query string is supposed to pass through untouched, but if it isn't you can explicitly grab it as above. The %1 is a backreference to the match from the first RewriteCond, containing the query string.
I simplified your original two RewriteConds into one by matching with or without the leading www. via the (www.)? portion of the rule.
This is the code that worked. All props to a link!David Ravetti.
#Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain.com$
RewriteRule ^query.php$ http://newdomain.com/subdir/file.php?pub=123456 [L,QSA]
Related
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]
It seems a very eask task, but I couldn't make it for hours after reading too much tutorial. Please help..
I need to redirect
http://example.com/myfolder/myfile.php?type=1&add=20
to this address:
http://example.com/newfolder/mytasks.xml
I tried too many. My last tryout was this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/myfolder/myfile.php?type=1&add=20$ /newfolder/mytasks.xml [R=301,NC,L]
</IfModule>
Use this rule instead:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+myfolder/myfile\.php\?type=1&add=20 [NC]
RewriteRule ^ /newfolder/mytasks.xml [R=301,L]
Remember:
RewriteRule match doesn't start with a slash /
RewriteRule doesn't match query string, it matches only Request URI
If you also want the query type=1&add=20 removed, something like this should work:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} type=1&add=20 [NC]
RewriteCond %{REQUEST_URI} !/newfolder/ [NC]
RewriteRule ^myfolder/myfile\.php /newfolder/mytasks.xml? [R=301,NC,L]
Redirects:
http://example.com/myfolder/myfile.php?type=1&add=20 to
http://example.com/newfolder/mytasks.xml
For silent mapping, replace [R=301,NC,L] with [NC,L]
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://agilerent.com$ [NC]
RewriteRule ^(.*)$ http://www.agilerent.com/$1 [R=301,L]
this is not working, while this is working:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^http://agilerent.com$ [NC]
RewriteRule ^(.*)$ http://www.agilerent.com/$1 [R=301,L]
with the negation in front of the condition. I've read a lot of material about .htaccess in last hour, but I can't realize yet what am i doing wrong...
%{HTTP_HOST} contains domain name ONLY, e.g. example.com, www.example.com etc and does NOT include protocol. Therefore:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^agilerent\.com$ [NC]
RewriteRule ^(.*)$ http://www.agilerent.com/$1 [R=301,L]
basally I need to redirect
http://www.old-domain.com/news.php?NewsID=30888
to
http://www.new-domain.com/news.php?NewsID=30888
using htaccess however only if the query string is as above. Any other query strings I need to continue to go tohttp://www.old-domain.com/news.php?NewsID=whatever_querystring.
So I need to match the 30888 and then redirect to a whole new site including the news.php?NewsID=30888.
Thanks in advance
Put this code in your .htaccess and try;
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{QUERY_STRING} ^NewsID=30888 [NC]
RewriteCond %{HTTP_HOST} ^www\.old-domain\.com$ [NC]
RewriteRule ^ http://www.new-domain.com%{REQUEST_URI}?%{QUERY_STRING} [R=301,L]
You have to test your Query string and the host name:
RewriteCond %{QUERY_STRING} NewsID=30888 [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$ [NC]
RewriteRule ^/(.*) http://www.new-domain.com/$1 [L,R]
I want to redirect "http://www.suma.ir/product.php?id_product=12" to "http://www.suma.ir/product.php?id_product=508" but I'm having trouble. The URL path should stay the same, all I want to do is change the ID in the query string. What do I need to do to make this work?
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^suma\.ir$ [NC]
RewriteRule ^(.*)$ http://www.suma.ir/$1 [R=301,L]
# This is the part that isn't working
Redirect 301 /product.php?id_product=12 http://www.suma.ir/product.php?id_product=508
The mod_alias Redirect directive doesn't look at the parameter string, so your Redirect statement will never match. Instead, you'll need to use mod_rewrite. You can do something like the following:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^suma\.ir$ [NC]
RewriteRule ^(.*)$ http://www.suma.ir/$1 [R=301,L]
RewriteCond %{QUERY_STRING} (^|&)id_product=12(&|$)
RewriteRule ^product\.php$ /$0?id_product=508 [R=301,L]