将所有请求重定向到index.php并清除URL

时间:2014-01-28 20:18:30

标签: .htaccess redirect rewrite

我想知道是否可以将所有请求重定向到index.php不存在的文件/目录,然后清理网址。

所以,当我转到www.example.com/test/1时,我希望将其重定向(重写?)到www.example.com

我尝试了以下操作并且正确加载了index.php,但它仍然在网址栏中显示www.example.com/test/1 ...

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]

当然我还是希望我的css和js正确加载......

1 个答案:

答案 0 :(得分:1)

试试这个。如果我理解,你想用它来重定向404找不到的方法吗?

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [R=301,L]

或者这可能没有index.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [R=301,L]
相关问题