Reputation: 2301
I disabled directory browsing in my .htaccess file, and recently I have changed my default index page, which works. But now when I browse to: domain.com/images/ it's suppose to give me a 403 forbidden error, but it just goes to the index page '/en/index.php' itself.
#Turn rewrite engine on
RewriteEngine on
#Disable directory browsing
Options -Indexes
#Default index page
DirectoryIndex /en/index.php
ErrorDocument 404 /error.php
#Add trailing slash
RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*) /$1/ [R=301,L]
#Remove trailing slash
RewriteCond %{REQUEST_URI} !^/en/$
RewriteCond %{REQUEST_URI} !^/fr/$
RewriteCond %{REQUEST_URI} !^/images/$
RewriteCond %{REQUEST_URI} !^/includes/$
RewriteCond %{REQUEST_URI} !^/stylesheets/$
RewriteRule ^/$ /$1 [R=301,L]
#Redirect non-www to www
RewriteCond %{HTTP_HOST} \.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
#Add trailing slash
RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*) /$1/ [R=301,L]
#English
RewriteRule ^what-is-minecraft/$ /en/what-is-minecraft.php [NC,L]
RewriteRule ^getting-started/$ /en/getting-started.php [NC,L]
RewriteRule ^mods/$ /en/mods.php [NC,L]
RewriteRule ^best-mods/$ /en/best-mods.php [NC,L]
RewriteRule ^terms-of-service/$ terms-of-service.php [NC,L]
RewriteRule ^privacy-policy/$ privacy-policy.php [NC,L]
#French
RewriteRule ^fr/cest-quoi-minecraft/$ /fr/cest-quoi-minecraft.php [NC,L]
RewriteRule ^fr/demarrage/$ /fr/demarrage.php [NC,L]
RewriteRule ^fr/mods/$ /fr/mods.php [NC,L]
RewriteRule ^fr/meilleurs-mods/$ /fr/meilleurs-mods.php [NC,L]
RewriteRule ^fr/$ /fr/index.php [NC,L]
Can anybody figure out what's the problem?
EDIT: Posted my complete .htaccess code.
Upvotes: 0
Views: 98
Reputation: 19528
With this code you would not need to remove the trailing slash as it is not being appended to the redirect of php files and you don't need to worry about existent files or folders as they won't be rewritten either.
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
ErrorDocument 404 /error.php
#Redirect non-www to www
RewriteCond %{HTTP_HOST} \.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Remove the php extension
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,L]
# Does not end with trailing slash redirect
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^ %{REQUEST_URI}/ [R=301,L]
# To internally redirect /anything to /anything.php if /anything.php exists
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/en [NC]
RewriteCond %{DOCUMENT_ROOT}/en/$1\.php -f
RewriteRule ^(.+?)/?$ en/$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
Upvotes: 1