开发者

PHP URL Rewriting

I am setting up some rewrite rules on an Apache server using mod_rewrite. I was wondering if it was possible to write a rule that will basically re-direct 开发者_如何学JAVAthe user to the home page if the page is not found i.e.

http://example.com/test  <-- does not exist

However, I would like if the user was to navigate to this domain they are automatically re-directed to:

http://example.com/

With this in mind, I don't want the URL to still display "http://example.com/test" I would like the URL to update itself to become "http://example.com/".


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ http://domain.com/ [L,R=301]

Essentially, "if the requested filename is not a file or directory, redirect".


I wouldn’t use a HTTP redirection but instead send an error document together with the proper error status code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜