0

I have a Drupal7 site hosted in a sub-directory and site can be access following with directory path and trailing slash:

http://mydomain.com/dir1/dir2/ (with the trailing slash).

I’m looking to access this site without the trailing slash:

http://mydomain.com/dir1/dir2

I tried with the DirectorySlash Off in the .htaccess file. But it gives Access forbidden error when accessing site without trailing slash.

Then I created a new .htaccess file in the ../dir1 and tried to rewrite the url to get the main page content when user access site without trailing slash.

<IfModule mod_rewrite.c>
    DirectorySlash Off
    RewriteEngine on
   Options +FollowSymLinks
   RewriteRule ^dir2$ dir2/index.php
</IfModule>

Again I’m getting the same issue “Access forbidden”. Is there anything to do in .htaccess file in Drupal root after setting these rules?

Any idea how to access Drupal site hosted in a sub-directory without trailing slash?

gajaba
  • 1

1 Answers1

0

Try this. But I'm not tested it.

Basically the trick here is to use a 301-redirect to remove the trailing slash at the end of all your URL’s. The code to put in your .HTACCESS

#remove trailing slashes
RewriteCond %{HTTP_HOST} !^\.domain\.com$ [NC]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

There is a Drupal plugin also. According to their description looks like it will match to your requirement. Give a try.

https://drupal.org/project/globalredirect

Achintha Samindika
  • 1,944
  • 1
  • 20
  • 31
  • Thanks Achintha. i think this is working fine for the site domain. What I'm looking for is, how to remove trailing slash when we access directories. like http://mydomain.com/foo/bar/. we can use "DirectorySlash Off" in the .htaccess file to remove trailing slash. But it gives "Access forbidden" error. – gajaba Aug 07 '13 at 06:26
  • Have you checked this? But its working Apache 2.4+ http://stackoverflow.com/a/9409661/1465973 – Achintha Samindika Aug 07 '13 at 06:39
  • yes. getting 403 error (Access forbidden!) for this setup as well. – gajaba Aug 07 '13 at 06:55