.htaccess重写特定的现有目录

时间:2013-01-05 19:13:45

标签: .htaccess mod-rewrite rewrite

我正在尝试获取现有目录/ blog(以及类似/blog(/*)),以重定向到index.php以及任何不存在的目录,如下所示。

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

RewriteRule ^blog(.*)$ /index.php/$1 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ /index.php/$1 [L]

ErrorDocument 404 404.shtml

到目前为止,我已尝试了大约一千件事,但没有任何效果。

2 个答案:

答案 0 :(得分:0)

您是否在httpd.conf中将allowoverride设置为all?

答案 1 :(得分:0)

尝试以下方法:

RewriteEngine On

RewriteRule blog /index.php [L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]