0

Currently, when a request is made for a URL that is not a directory, my .htaccess is set up to remove any trailing slash. The problem is, that is causing test.domain.com/order.php/ to be redirected to test.domain.com/test/order.php instead of test.domain.com/order.php. It works perfectly when not in a subdomain.

Here is the .htaccess code I am using to remove trailing slashes:

    #if it's not a directory
    RewriteCond %{REQUEST_FILENAME} !-d
    #and it has a trailing slash, then redirect to URL without slash
    RewriteRule ^(.+)/$ /$1 [L,R=301]

Somehow, the subdirectory the subdomain serves from is being added to the URL in addition to the subdomain already there. How can I remove the trailing slash without adding /test?

Edit:

Here is the full .htaccess:

    RewriteEngine On

    Options +SymLinksIfOwnerMatch
    Options -Indexes
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ /$1 [L,R=301]
CLL
  • 1,312
  • 3
  • 13
  • 26
  • Are there more rules in this file or this is the only one? – anubhava May 26 '14 at 03:33
  • Added full htaccess content to post – CLL May 26 '14 at 03:39
  • If this is in DocumentRoot of parent domain it won't execute for subb domain (unless subdomain is not setup right). Can you show VirtualHost entry of sub domain? – anubhava May 26 '14 at 03:48
  • I don't believe I have access to that—the site is on a shared server. However, based on your answer, I put the rule in the htaccess file of the subdirectory, and it now works as intended. Thank you! – CLL May 26 '14 at 04:01

1 Answers1

0

After seeing anubhava's comment under my question, I decided to put the remove trailing slash rule in an .htaccess file in the subdomain's subdirectory. I also prevent the rule in the document root .htaccess from affecting the subdirectory (since it has its own rule):

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{HTTP_HOST} !^test\. [NC]
    RewriteRule ^(.+)/$ /$1 [L,R=301]

It now works as intended for the main site, as well as the subdomain.

CLL
  • 1,312
  • 3
  • 13
  • 26