I would like to redirect all URLs as follows
http://domain.com/?s=25 ...> http://domain.com/s=25.html
For each URL I can do the folowing:
RewriteCond %{QUERY_STRING} (^|&)s\=25($|&)
RewriteRule ^$ /s=25.html?&%{QUERY_STRING}
I want to rewrite everything following the "?"
For example:
/?s=25 ...> /s=25.html
/?cat=2 ...> /cat=2.html
/?page_id=25 ...> /page_id=25.html
How can I do this for multiple files with a single rule?
Any help would be much appreciated!
This should get you with one rule. Give this a try and let me know.
RewriteEngine on
RewriteCond %{QUERY_STRING} (?:^|&)(page_id|cat|s)=(.+)(?:$|&)
RewriteRule ^$ /%1=%2.html [L,QSA]
Related
I have problem with htaccess rewrite rule.
I have page for example:
www.oldpage.com/55,city.html?partner_id=7
www.oldpage.com/subpage/158,blog.html?partner_id=8
And I want to rewrite this page on:
www.newpage.com/55,city.html
www.newpage.com/subpage/158,blog.html
It is possible? Maybe I must redirect links with .html?partner_id on normal .html, after on newpage?
You can use the QSD flag (query string discard)
RewriteRule .* ww.newpage.com/$1 [NC,QSD]
I solved this problem by adding in .htaccess for newpage.com this code:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^partner_id=([0-9]*)$
RewriteRule ^(.*)$ /$1? [R,L]
I need a general permament redirection rule for every
mysite.com/read.cfm?id=NUMBER
to
mysite.com/?p=NUMBER
I'm trying something like:
RewriteRule ^(.+?)\read.cfm$ /?p=$1 [L,NC,R]
Thanks in advance.
To redirect /read.cfm?id=12345 to /?p=12345 you can use :
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^read.cfm$ /?p=%1 [L,NC,R]
i am trying to change the url using htaccess rewrite
i want to change this url
page/details.php?name=abcdef&id=18
to
page/abcdef
Here my sample code for this
RewriteEngine On
RewriteRule ^company/([A-Za-z0-9-]+)/$1 company/details.php?name=$1&id=$2 [R=301,L]
this is not working, and also i was tried many code but not working,please help me to find htaccess code for this url
Thanks advance
This should do what you're after:
RewriteCond %{QUERY_STRING} ^.*name=([a-zA-Z0-9]*).*$
RewriteRule ^page/(.*)$ page/%1? [R=301,L]
Try this one:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^name=(.*)&id=(.*)$
RewriteRule ^page/(.*)$ /page/%1? [R=301,L]
This will check for these 2 parameters in the query string.
Is it possible to redirect based on an url that would be as:
www.url.com/stuff.php
But not redirect if the url contained any characters after the php, as such:
www.url.com/stuff.php?variables=values&othervariable=othervalue&etc=more
I have no clue how to wriite this either.
Thanks in advance!
Edit: basically I need the redirect to happen to www.url2.com only if www.url.com ends with .php, but not if the .php is followed by variables.
try
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/site.com/?$ /site.com/cart.php [R=301,NC,L]
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?cart.php$ / [L,R=301]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^stuff.php$ RELATIVE_OR_ABSOLUTE_URL_HERE [L]
I have a dynamic query string that I need to pass via an .htaccess redirect. For example:
I need to redirect this URL: http://mysite.com/page1?action=signup&var2=dynamicVar
To this: http://mysite.com?action=signup&var2=dynamicVar
I know this is pretty simple, but I'm really not sure what type of rule/syntax would work for this.
Any help is greatly appreciated!
If you already have .htaccess then simply add this line:
RewriteRule ^page1/?$ page2 [L,R,QSA,NC]
Update: Based on your comments:
RewriteCond %{QUERY_STRING} (^|&)action=signup(&|$) [NC]
RewriteRule ^page1/?$ / [L,R,QSA,NC]
RewriteRule ^page1(.*)$ /page2$1 [L,R=301]
Input
http://mysite.com/page1?action=signup&var2=dynamicVar
this is the rewrite rule
RewriteRule ^page1?(.*)$ /?$1 [L,R=301]
redirect to
http://mysite.com/?action=signup&var2=dynamicVar
this will redirect all request o page1 with get parameters to http://mysite.com
Use %{REQUEST_URI}
fi.:
RewriteCond %{HTTP_HOST} ^website\.(.+)$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
rewrites anything that starts with "website" to "www.website..." including the querystring (by use of %{REQUEST_URI})