: How to eliminate space on .htaccess Somehow a space was introduced in some of my URL like: /marques-voiture/Ford /marques-voiture/ Ford I attempted to correct that with the following rule on
Somehow a space was introduced in some of my URL like:
/marques-voiture/Ford
/marques-voiture/ Ford
I attempted to correct that with the following rule on .htaccess
RewriteCond %{REQUEST_URI} ^/marques-voiture/s.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /marques-voiture/s(.*) www.example.com/marques-voiture/ [R=301,L]
Regexp's seem to be correct according to regexp101.com, but .htaccess is solemnly ignoring that.
I do have a number of other rules on .htaccess, but I do not see a conflict there.
Any ideas?
More posts by @Shanna517
1 Comments
Sorted by latest first Latest Oldest Best
RewriteRule /marques-voiture/s(.*) www.example.com/marques-voiture/ [R=301,L]
Your problem is probably the slash prefix on the RewriteRule pattern. In per-directory .htaccess files the directory-prefix is first removed from the URL-path that is matched. The directory-prefix always ends with a slash, so the URL-path that is matched never starts with a slash. So, the above rule never matches, not because of the space, but because of the slash prefix!
So, try the following instead:
RewriteRule ^marques-voiture/s(.*) www.example.com/marques-voiture/ [R=301,L]
You also don't need the first RewriteCond directive that checks against the REQUEST_URI - this is doing the same thing as the RewriteRule pattern.
And you don't need to escape slashes in most Apache regex (there are no delimiters).
Make sure you clear your browser cache, as any (erroneous) 301s will have been cached by the browser.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.