htaccess url rewrite:example.com/admin/.php> example.com/admin/index

时间:2012-02-20 13:48:21

标签: .htaccess mod-rewrite url-rewriting

我正在使用这个mod重写:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^example.nl$ [NC]
RewriteRule ^(.*)$ http://example.nl/$1 [L,R=301]

但是我转到页面:http://www.example.nl/admin/ 它必须将我重定向到http://www.example.nl/admin/index 相反,我得到404 errorpage(在此服务器上找不到请求的URL /admin/.php。)

如何将子图重定向到索引页?

我应该在所有子图中使用此代码吗? :

Redirect 301 /admin/ http://www.example.nl/admin/index

或者有更好的选择吗?

1 个答案:

答案 0 :(得分:1)

RewriteEngine On
RewriteBase /

#add these
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) /$1/ [R,L]

RewriteCond %{HTTP_HOST} !^example.nl$ [NC]
RewriteRule ^(.*)$ http://example.nl/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]