.htaccess重定向文件夹链接到index.php路由页面

时间:2013-06-04 10:10:50

标签: .htaccess routing directory

我的.htaccess文件如下所示:

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

我有一些<a>链接等于文件夹名称。 E.g。

www.mysite.com/test/scripts/ is a folder path
<a href="/test/scripts/"> is the link

现在我的问题是,如果链接指向某个文件夹,我会收到403 - Forbidden错误。 如何修改我的.htaccess,以便将匹配文件夹的链接重定向到index.php页面,这是一个路由页面?

1 个答案:

答案 0 :(得分:0)

我通过添加!解决了我的问题。这是因为如果URL不是文件夹,它会维护此URL,否则会将所有URL重定向到index.php。

完整代码:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
相关问题