0

Hello I have the following problem: I have some pages (php includes) which I load them like this

http://www.domain.com/news/

they work perfect. But if I remove the trailing slash

http://www.domain.com/news

this happens -> http://www.domain.com/news/?page=news&request=

Here are my htaccess rules:

RewriteEngine on

<IfModule mod_gzip.c>
    mod_gzip_on       Yes
    mod_gzip_dechunk  Yes
    mod_gzip_item_include file      \.(html?|txt|css|js|php|pl|jpg|png|gif)$
    mod_gzip_item_include handler   ^cgi-script$
    mod_gzip_item_include mime      ^text/.*
    mod_gzip_item_include mime      ^application/x-javascript.*
    mod_gzip_item_exclude mime      ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>




Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)(.*)$ /index.php?page=$1&request=$2

PS. Could it by because I have a news folder in the root document as well ?

1
  • What is the desired result if you visit domain.com/news/? Commented Dec 12, 2012 at 23:14

2 Answers 2

1

Yes, it's because you have a news/ folder in the root. Your Rewrite Condition is looking for anything that isn't a file (i.e. !-f) or a directory (!-d). Try renaming your news/ directory in the root.

If you must, you can force domain.com/news to rewrite to domain.com/news/ by doing the following:

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]
Sign up to request clarification or add additional context in comments.

1 Comment

Yep the directory was the issue, Thank you :)
0

This is a mod_dir issue. It's redirecting the browser when it thinks a URL maps to a directory (even if it's later determined not to) to ensure that a trailing slash is appended to the end. See this recent explanation that I posted in another question.

Like in the other answer, you can either turn off DirectorySlash or ensure that all of the affected URL's get redirected with a trailing slash via mod_rewrite (so that the rewrite and the redirect happens within the same module):

  1. Turn off mod_dir by including a DirectorySlash Off. This makes it so mod_dir won't redirect the browser, but note that there are other consequences to turning this off. You can add that directive in your htaccess file.

  2. Handle the trailing slash in mod_rewrite:

    RewriteEngine On
    Options -MultiViews
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule ^(.*)$ /$1/ [L,R=301]
    

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.