2

I ran a page seo and it said I needed to remove the trailing slash because it could cause duplicate content. So I found this rule:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

and added it to the htaccess but now I can't pass the Billing Information step in the onepage checkout.

Is this rule correct? Why can't I pass the Billing step?

4 Answers 4

3

This is not required if you activate the canonical URLs under System > Configuration. This will prevent Google from indexing the page on different URLs

canonical settings

3
  • I was also thinking about the other search engines. Use Canonical Link Meta Tag For Categories because each category page is different. I use this: print_r ($_SERVER['QUERY_STRING']); in my meta title tag to display p=2 so I don't get duplicate title tag warnings. I use Canonical for pages thou. Wonder why removing the slash makes it where magento can't check out?
    – Freejoy
    Commented Jan 17, 2016 at 15:46
  • It will also work for other search engines. This is basically the way to go and will solve a lot more issues next to slash also regarding layered navigation and pagination. Commented Jan 18, 2016 at 7:41
  • @Sander Thank you for your answser. I just want to let you know that it will not work in the case of other page (CMS Page and cart page etc) Commented Jul 21, 2017 at 6:35
2

This removes trailing slashes and redirects uppercase to lowercase as well

# Remove trailing slashes (consider backend)
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/downloader.*$
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.*)/$ /$1 [L,R=301] 

# Eugene: Redirect uppercase to lowercase
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} [A-Z]
# need RewriteMap lc int:tolower in VirtualHosts httpd.conf
RewriteRule (.*) /${lc:$1} [R=301,L]
2
  • where do you add this code? Commented Feb 3, 2020 at 13:42
  • .htaccess (usually in www folder for Apache httpd web server), see the comment about lc function in httpd.conf as well (last line) Commented Feb 6, 2020 at 3:09
1

You can use below code in your .htaccess file.

# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]

I have used this and this is working fine for me.

When you will enable the Use Canonical Link Meta Tag For Categories and Use Canonical Link Meta Tag For Product in System > Configuration > Catalog > Search Engine Optimization. This is right that slash will not effect your Seo ranking(Duplicate URL Issue). But, this will work for only Categories and Products. It will not work for other pages.

1
  • Hi @vikas verma where should we need to add this in .htaccess file please advise? Commented Aug 18, 2020 at 14:21
0

Here is a more recent rewrite rool that also forces to use https (useful if apache is used behind proxy that handles SSL):

# Remove trailing slashes (consider backend)
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/downloader.*$
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.*)/$ https://%{HTTP_HOST}/$1 [L,R=301]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.