Natalie
Natalie

Reputation: 451

htaccess 3 level directory rewrite rule

What is wrong with my htaccess file? I want to be able to access my site like this: site.com , site.com/en, site.com/en/dir, site.com/en/dir/subdir. However I get 404 error (only site.com points to index.php , urls like site.com/en or site.com/en/dir returns 404 error. mod_rewrite is on)

RewriteEngine on 
Options -Indexes
Options +FollowSymlinks

AddDefaultCharset utf-8

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9_]+)(/?)$ index.php?route=$1 [QSA,L]
RewriteRule ^([a-zA-Z0-9_]+)(/?)([a-zA-Z0-9_\-]+)(/?)$ index.php?route=$1&subroute=$3    [QSA,L]
RewriteRule ^([a-z]+)(/?)([a-zA-Z0-9_]+)(/?)([a-zA-Z0-9_\-]+)(/?)$ index.php?language=$1&route=$3&subroute=$5 [QSA,L]

Upvotes: 1

Views: 207

Answers (2)

Natalie
Natalie

Reputation: 451

The reason was in notepad 6.5.5 which removes line breaks.. in utf8 without dom encoding Online htaccess tester helped to find the problems

Upvotes: 0

anubhava
anubhava

Reputation: 784908

Make sure .htaccess and mod_rewrite are enabled. Once they are enabled you can use:

AddDefaultCharset utf-8
Options +FollowSymlinks -Indexes
RewriteEngine on 
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]

RewriteRule ^(\w+)/?$ index.php?route=$1 [QSA,L]
RewriteRule ^(\w+)(/?)([\w-]+)/?$ index.php?route=$1&subroute=$2 [QSA,L]
RewriteRule ^([a-z]+)/(\w+)/([\w-]+)/?$ index.php?language=$1&route=$2&subroute=$3 [QSA,L]

Upvotes: 1

Related Questions