Remove amp from url .htaccess - .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

Related

Remove subfolder using htaccess

I know that this has been requested a million times but i haven't found an answer.
Basically I want to remove amp from my site but I've a million pages indexed using /amp so if I remove it this will cause a mess.
What I want to do is to redirect all the url like these
https://*/amp
will go to the same url without amp.
For example an article with this url
https://www.tuttosullapostaelettronica.it/blog/come-e-fatta-una-mail/amp
will be redirected to the same article without /amp like
https://www.tuttosullapostaelettronica.it/blog/come-e-fatta-una-mail
This has to be valid for whatever article url that end in /amp that has to be the /amp removed
Thanks!
Assuming you need to remove amp on requests to the document (first example) and /amp on requests to other URLs then you would need a rule like the following using mod_rewrite, near the top of the .htaccess file:
RewriteEngine On
RewriteRule ^(?:(.+)/)?amp$ /$1 [R=301,L]
The regex ^(?:(.+)/)?amp$ matches both amp and <something>/amp and removes amp or /amp respectively.
Test first with a 302 (temporary) redirect to avoid potential caching issues.

Redirect old url to new url with .htaccess redirection

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 / -_ .

URL rewrite with PHP and .htaccess

Can anybody advise how I can rewrite the following URL:
www.mydomain.com/products.php?product=product-name
At the moment, it works fine (I use $_GET to grab the unique product name and use it on my page) but I would like to be able to use the following URL format to get the same outcome:
www.mydomain.com/products/product-name
I've seen a few similar examples on here but cannot get them to work with my situation.
This is how your .htaccess will look like,
RewriteEngine On
RewriteRule ^products/([A-Za-z0-9-]+) /products.php?product=$1 [NC,L]
RewriteEngine On this is used to turn on the rewrite engine.
^products/([A-Za-z0-9-]+) matches the URL like (www.mydomain.com/products.php?product=product-name) where product name can be one or more of any combination of letters, numbers and hyphens.
And use that combination of letters in /products.php?product=$1 where $1 denotes the Product name.

Rewrite rule for seo - title in url

Lets say I want users to be able to type this url in:
www.website.com/blog/2453/I-gained-0.1%-more-scripting-knowledge-!
I'm trying to include title information in the url for seo benefits.
I also want to include an id for my query. Effectively I want to pick up the id and ignore the title stuff that comes after, bearing in mind its user generated text so could contain any special characters in it.
How can I write a .htaccess rewrite rule so that the server reads it as the following with the appropriate GET data:
www.website.com/blog.php?id=2453
This is what I have tried but frankly I am way out of my depth here:
RewriteRule ^blog/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ blog.php?id=$1 [NC,L]
The rewrite rule you are using should work except for the ., %, and ! characters that are in your URL. The % characters is not safe to use in URLs because it has a special meaning in the URL syntax. I wouldn't use exclamation points either.
If the ID is always going to be numeric, use ([0-9]+) instead of ([A-Za-z0-9-]+).
Try this URL:
www.website.com/blog/2453/I-gained-0.1-more-scripting-knowledge
With this rule:
RewriteRule ^blog/([0-9]+)/[A-Za-z0-9\-\.]+/?$ blog.php?id=$1 [NC,L]

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