0

I have a two-part issue.

  • I am trying to implement a redirect only for the homepage URL to render with a trailing slash. Example: redirect www.domain.com to www.domain.com/ BUT allow all other URLs to render without a trailing slash.

End Goal:

www.domain.com/
www.domain.com/pages
www.domain.com/pages/post-name
  • This get complicated because there is one WordPress install with one .htaccess file but 6 other sites (with different domains) installed under the main WP install. I need to implement the trailing slash only on the homepage URL for a site that is mapped under the main install and shares the same .htaccess file with the main instal domain. So a rewrite base will only affect the main install domain, not the other 6 sites.

This is the first time I have encountered this kind of structure and it has me totally confused. Is this even possible to achieve? Thanks for any help!

animuson
  • 53,861
  • 28
  • 137
  • 147
Cara
  • 1
  • 1
  • 1
  • May i know the purpose of this? because even if you put www.domain.com/ to a browser it automatically strips the trailing slash. Thanks – Vasanthan.R.P Nov 17 '11 at 11:33
  • @Vasanthan.R.P browsers automatically adds the slash when requesting the url (the are present in the http headers). But they indeed don't show it, so there is indeed no point for this question – Gerben Nov 17 '11 at 19:44
  • @Vasanthan R.P. the reason is to consolidate equity to one URL. I don't want people or search engines the ability to reach without a trailing slash, so all equity will be placed on the trailing slash version. Thank you for your comments! – Cara Nov 18 '11 at 20:34

1 Answers1

2

There really is no need to force a trailing slash when there is no path, because if the path is empty, it is implied to be / already. Having the slash there or not will make absolutely no difference in the rendering of your pages or how Apache handles the request. Not to mention, redirecting users to have the / appended will just cause them to waste an extra HTTP request.

However, you can prevent Apache from adding the / to URLs which resemble a directory by using this:

DirectorySlash Off

Which will prevent /pages from becoming /pages/. Although, if a user manually types it in with the / at the end, it will still be there. Again, redirecting just to remove a / at the end is a waste.

animuson
  • 53,861
  • 28
  • 137
  • 147
  • 1
    There is a reason for trailing slash, but only with physical directories, and not wordpress' SEO friendly rewritten URLs. See [Security Warning](http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryslash) in the DirectorySlash docs – Jon Lin Nov 18 '11 at 01:27
  • Hi animuson, I appreciate your answer. That is exactly what has me confused. Because the / is implied I don't think this is possible to redirect the homepage only. Is that correct? My goal is to consolidate equity to one URL. I don't want people or search engines the ability to reach the URL without a trailing slash, so all equity will be placed on the trailing slash version. – Cara Nov 18 '11 at 20:36