How to ignore apostrophe in url via .htaccess?

Member

by zion , in category: SEO , 6 months ago

How to ignore apostrophe in url via .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by annabell_mcdermott , 6 months ago

@zion 

To ignore apostrophes in URLs using .htaccess, you can use the following code:

1
2
3
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([^']*'[^']*)$
RewriteRule ^(.*)$ /%1 [L]


Explanation:

  • RewriteEngine On - enables the rewriting engine.
  • RewriteCond %{REQUEST_URI} ^/([^']*'[^']*)$ - checks if the requested URI contains an apostrophe.
  • RewriteRule ^(.*)$ /%1 [L] - redirects the request to a modified URL that removes the apostrophe.


This code will remove the apostrophe from the URL and redirect to the modified URL, effectively ignoring the apostrophe.


Note that the .htaccess file needs to be placed in the root directory of your website. Additionally, ensure that the mod_rewrite module is enabled for Apache.