Redirect old url to new url with .htaccess redirection - .htaccess

I am trying to redirect all of the following type of links:
LINKS TO BE REDIRECTED:
https://www.canvas-events.co.uk/venues/landmark-buildings
REDIRECT TO THIS LINK DYNAMICALLY:
https://www.canvas-events.co.uk/hire/venues/landmark-buildings
NOTE: I want to redirect all url's which contains alphabets naming instead of integers because we have an another route which has the same route structure too, i.e. venues/293 & /venues/landmark-buildings the only difference is the use of alphabet based delimiter instead of integer one. I need to redirect the link with alpahbets delimiter not the integer one.
Thanks

This should work :
RedirectMatch 301 ^/venues/([A-Za-z/-_]+)/?$ https://www.canvas-events.co.uk/hire/venues/$1
The pattern above only accepts characters ranging from A-Z a-z and some URL characters / -_ .

Related

URL Rewrite keep %20 in Query String

I am trying to make a rewrite rule to move all pdf's on my site to point to a specific page and then use a Query String as the pdf's current file path to do a look up in a dictionary to see if that url is in my dictionary if it is redirect them to the correct page. The catch is my dictionary of urls has %20 and when I pull the query string it turns the %20 in a space. Thanks for any and all help.
Can you rewrite it to keep the %20 in the query string?
Example URL: /example/example/Big%20Small%20Something%20Pad.pdf
My Rewrite:
RewriteRule ([^/]*)\.pdf$ /redirectPDF.aspx?pdf=$1.pdf [NE,QSA]
Current Query String Output: Big Small Something Pad.pdf
What I want it to look like is Big%20Small%20Someting%20Pad.pdf
Try removing the NE flag. According to ISAPI docs:
http://www.helicontech.com/isapi_rewrite/doc/RewriteRule.htm:
noescape|NE
Don't escape output. By default ISAPI_Rewrite will encode all non-ANSI >characters as %xx hex codes in output.
So it looks like you simply want to omit the NE so that it'll encode the output like it does by default.
RewriteRule ([^/]*)\.pdf$ /redirectPDF.aspx?pdf=$1.pdf [QSA]

Redirect to URL with umlauts or accents via .htaccess

To redirect to a new URL that contains diacritics via .htaccess, what is the correct and safe way?
Can I somehow set the .htaccess file to UTF-8 and just use the non-ASCII characters, e.g.:
redirect 301 / http://www.bücher.ch/
Need I use the ACE string instead, e.g.:
redirect 301 / http://www.xn--bcher-kva.ch/
Is urlencode the way to go? I tried the following without success:
redirect 301 / http://www.b%C3%BCcher.ch/
For context, the following page on internationalized domain names (IDN) has a section about the technical solution to include accents and umlauts in domains.
In the domain part, you must use ASCII Compatible Encoding (ACE).
In the rest of the URL, you use urlencode. So, in .htaccess…
http://www.bücher.ch/schöne/
…needs to be written as…
http://www.xn--bcher-kva.ch/sch%C3%B6ne/

Remove amp from url .htaccess

I want to remove amp from url. htaccess
special characters create duplicate content
example
/b-amp-b.html
/b-b.html
how can I do?
I have a problem in the url rewriting, two pages are created equal a / b-amp-b.html the other /b-b.html that's why i want to remove amp
Assuming that you mean the & character and not the word "amp", you'd do something like this:
RedirectMatch ^/(.*)[&%\^#](.*)$ /$1$2
The [&%\^#] is where you'd fill in with all the "special" characters that you don't want

301 redirect URL with query string, removing part of the beginning URL, keeping the full query at the end

I'm trying to find a redirect that will remove part of a URL (in the middle), but leaves the query string in place at the end.
I can do this fine via a single url redirect, but there are hundreds of these urls so I'm trying to find a rule that might be able to do for all of them in one fell swoop, so i don't have to make one for each and any new ones will get redirected automatically.
I'm trying to remove 'search.php' from the urls, here is an example:
www.site.com/products/search.php?rPage=/items/listing/detail_handler.jsp?code=219592&units=Feet&item_id=2624472
to redirect to:
www.site.com/products/?rPage=/items/listing/detail_handler.jsp?code=219592&units=Feet&item_id=2624472
Thanks for your time.
According to the documentation, the query string is passed through unchanged by default
RewriteRule products/search.php http://www.site.com/products/ [L,R=301]

htaccess redirect url with space in it

Stupidly, I have sent out a newsletter without checking the links. One of which is broken so I want to handle this with htaccess.
My URL that is being linked to is:
http://www.domain.com.au/www.domain.com.au/campers-and-motorhomes/ne%20w-zealand/camper-rentals/
where the actual page is:
http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/
Note the space in new zealand as well as the additional www.domain.com.au
How can I set this up in htaccess?
Thanks
Since you don't have to manipulate the URL, you can use a simple Redirect:
Redirect /www.domain.com.au/campers-and-motorhomes/ne%20w-zealand/camper-rentals/ http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/
Edit If Apache doesn't like the space unquoted as %20, try quoting the whole thing with a real space in there:
Redirect "/www.domain.com.au/campers-and-motorhomes/ne w-zealand/camper-rentals/" http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/
Edit2 If it's appending a query string, you will need to use mod_rewrite to get rid of the querystring rather than a simple redirect, I'm afraid.
RewriteEngine On
# If the request starts with www.domain.com.au, it is the broken link
# Rewrite to the proper URL and put ? on the end to remove the query string
RewriteRule ^www\.domain\.com\.au http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/? [L,R=301]

Resources