how to execute RewriteRule same page with defferent query string? - .htaccess

I have this code in a .htaccess
RewriteEngine On
Options +MultiViews +FollowSymLinks
RewriteRule ^([a-zA-Z0-9-_]+)$ index.php?menu=$1 [L]
RewriteRule ^([a-zA-Z0-9-_]+)$ index.php?sub=$1 [NC]
The first RewriteRule has execute
but the second RewriteRule does not execute.
How to execute RewriteRule same page with different query string as like above example?

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]

Redirecting with htaccess

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]

htaccess RewriteRule to new domain keeping query string

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]

.htaccess RewriteRule without URL change in browser

I have .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^somedomain.com [NC]
RewriteRule ^(.*)$ http://www.somedomain.com/$1 [R=301,NC]
RewriteRule ^r/(.*)$ index.php?rid=$1 [NC]
But last condition performs redirect in browser when I request URL like www.somedomain.com/r/123 and show me URL like www.somedomain.com/index.php?rid=123. But I need call this script without URL change.
What's wrong?
You used the R=301 Try to use L just like following:
RewriteCond %{HTTP_HOST} ^somedomain.com [L]
RewriteRule ^(.*)$ http://www.somedomain.com/$1 [L]
RewriteRule ^r/(.*)$ index.php?rid=$1 [L]

.htaccess redirect one domain to another incliuding specific query string

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]

Resources