如何在.htaccess中重定向未定义的RewriteRule

时间:2012-05-02 23:31:07

标签: .htaccess

以下是我目前在.htaccess文件中写的内容:

RewriteEngine on
RewriteRule ^contact contact.php 
RewriteRule ^browse browse.php 
RewriteRule ^contact/ contact.php 
RewriteRule ^privacy privacy-policy.php
RewriteRule ^signup register.php
RewriteRule ^register register.php

因此,当用户请求http://mydomain.com/welcome时未在.htaccess文件中定义时,将导致“未找到404”页面。

相反,我想将未在.htaccess中明确定义的页面重定向到另一个脚本,并传递原始URL。我不想在这里使用ErrorDocument。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

RewriteEngine on

RewriteRule ^contact contact.php 
RewriteRule ^browse browse.php 
# why is contact the only one with a slash at the end?
RewriteRule ^contact/ contact.php 
RewriteRule ^privacy privacy-policy.php
RewriteRule ^signup register.php
RewriteRule ^register register.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /other.php [L]