I want to redirect many 100s of urls based on the end string "/reviews"
example.com/reviews/any-string.121/reviews to
example.com/reviews/any-string.121/
example.com/reviews/any-string.151/reviews to
example.com/reviews/any-string.151/
PS: 'any-string' means any string of alphabets.
Can anyone please help!
Try this:
RewriteEngine On
RewriteRule ^reviews/(.*)/reviews$ example.com/reviews/$1 [R=301,L]
Related
I have rewritten my site from asp to php. I need to redirect a few pages with multiple parameters.
These are a few of the old url's:
mysite.co.uk/productlist_paged.asp?cid=1&offset=10
mysite.co.uk/productlist_paged.asp?cid=1&offset=20
mysite.co.uk/productlist_paged.asp?cid=1&offset=30
mysite.co.uk/productlist_paged.asp?cid=1&offset=40
to the following new pages:
mysite.co.uk/Compare/Roland-Digital-Pianos/43/1
mysite.co.uk/Compare/Roland-Digital-Pianos/43/2
mysite.co.uk/Compare/Roland-Digital-Pianos/43/3
mysite.co.uk/Compare/Roland-Digital-Pianos/43/4
I was hoping to keep the number 43 out of the redirect as this a number that will change when products are added/removed.
cid=1 equals Roland-Digital-Pianos and e.g offset=10 is number 1 at the end of the url
Any help welcome
You could go with something like :
RewriteEngine On
RewriteCond %{QUERY_STRING} cid=1&offset=([0-9]+)0
RewriteRule ^productlist_paged.asp$ /Compare/Roland-Digital-Pianos/43/%1? [R=301,L]
There is an extra 0 at the end of the RewriteCond, otherwise, %1 would be 10 or 20 instead of 1 or 2.
The extra ? at the end delete the QUERY_STRING in the redirect url.
Note : I didn't add the ^ and $ in the RewriteCond, so that your url doesn't necessarly start/end with this QUERY_STRING, ie productlist_paged.asp?test=1&cid=1&offset=10&test2=1 will also fit the RewriteCond and get redirected.
Hope it helps !
I tried to search all pages but nothing to do for my request.
I need to REDIRECT the comlex link cause GOOGLE duplicate descriptions.
from:
http://www.3dstreaming.org/component/community/5816-stuart-edwards/profile.html?Itemid=0
to:
http://www.3dstreaming.org/you/edit-profile/5816-stuart-edwards.html
CONDICTIONS:
where "5816-stuart-edwards" is variable
part of the URL from "component/community" to "you/edit-profile"
replace from "5816-stuart-edwards/profile.html?Itemid=0" to "55816-stuart-edwards.html"
Many many thanks in advance.
Try the following:
RewriteEngine On
RewriteRule ^component/community/(.*)/profile.html$ /you/edit-profile/$1.html? [R]
RewriteRule ^you/edit-profile/(.*).html /component/community/$1/profile.html [L]
The above should change http://www.3dstreaming.org/component/community/5816-stuart-edwards/profile.html?Itemid=0 to: http://www.3dstreaming.org/you/edit-profile/5816-stuart-edwards.html
Here is my problem...
I have a to redirect a link like this:
site.com/virtualfolder/some-seo-friendly-keywork
to
site.com/folder/page.php?id=some-seo-friendly-keyword
In site.com there is no real folder "virtualfolder", it is virtual.
I have to take "some-seo-friendly-keyword" and use it as a query string
I think i have to firts match the folder "virtualfolder" and then capture the "some-seo-friendly-keyword", but how?
The some-seo-friendly-keyword is a string of characters and digits plus hypens so something like this below is realistic?
RewriteRule ^virtualfolder/([a-zA-Z0-9-])? folder/page.php?id=$1 [L]
I'm still strudying and trying mod_rewrite and it is like voodoo to me! :-/
Thank you very much for your help or your suggestions
Try with this code in htaccess:
Using the original url to show:
Rewriterule ^virtualfolder/([a-zA-Z0-9_-]+)$ folder/page.php?id=$1
Redirecting to end url using RedirectMatch (use the full URL in the second part):
RedirectMatch 301 ^/virtualfolder/([a-zA-Z0-9_-]+)$ http://www.site.com/folder/page.php?id=$1
Redirecting to end url using mod_rewrite (use the full URL in the second part):
Rewriterule ^virtualfolder/([a-zA-Z0-9_-]+)$ http://www.site.com/folder/page.php?id=$1 [R=301,L,NE]
More info here
Hi I'm not a programmer by any stretch of the imagination and am trying to do a multi 301 redirect in my htaccess file based on the following:
So I have a ton of urls all with similar naming conventions - here is a sample of 2.
http://www.hollandsbrook.com/garrett-at-gold/
http://www.hollandsbrook.com/garrett-ace-250/
These urls need to redirect to:
http://www.hollandsbrook.com/garrett-metal-detectors/garrett-at-gold/
http://www.hollandsbrook.com/garrett-metal-detectors/garrett-ace-250/
I could just redirect them 1 line at a time, but I'd like to use regex.
Here's what I was thinking so far but not working:
RewriteRule ^garrett-([a-z])/$ /garrett-metal-detectors/$1/ [R]
Basically i need to redirect any page right off the root that starts with "garrett-" to include the folder path of "garrett-metal-detectors".
Any thoughts would be MUCH appreciated. Many thanks in advance for your help.
if you want temprorary redirect use:
RewriteRule ^garrett\-([a-z0-9\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=302,L]
if you want permanent redirect use:
RewriteRule ^garrett\-([a-z0-9\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=301,L]
I'm am not an expert on Regular Expressions, but looks like your reg ex may be a bit off...
try:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^((garrett)(-[a-z0-9]).*)/$ /metal-detectors/$1/ [R]
This is looking fro anything starting with "garrett" followed by any letter/number/hyphen combo.
Note: having "garett" in the destination part give you a loop of redirects, so you may have to choose a different word, or remove it all together...
I'm need to redirect a a bunch of URL's through mod_rewrite. The URL structure is as follows:
www.mysite.com/somescript.php?&lang=asp&variable1&variable2
Needs to redirect to
www.mysite.com/somescript.php?&lang=php&variable1&variable2
So, basically, any URL with &lang=asp in it needs to be redirected to exactly the same URL but with &lang=php replacing &lang=asp.
Is there a way I can do this through .htaccess, perhaps with some sort of wildcard?
Thanks alot, I would appreciate your help.
Cheers,
Matt
Modifying the Query String
Change any single instance of val in the query string to other_val when accessing /path. Note that %1 and %2 are back-references to the matched part of the regular expression in the previous RewriteCond.
RewriteCond %{QUERY_STRING} ^(.*)lang=asp(.*)$
RewriteRule /path /path?%lang=php%2
Read this page for more info http://wiki.apache.org/httpd/RewriteQueryString