.htaccess路由所有,除非包含单词

时间:2019-01-18 23:03:15

标签: php .htaccess

因此,此刻,所有丢失的页面(404)都会重定向到domain.com/search.php并带有查询参数

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ search.php [QSA,L]

这很好用,但是,对于domain.com/submit,我有一个极端的情况,我需要它重定向到domain.com/submit.php

似乎无法弄清楚该怎么做。

预先感谢

2 个答案:

答案 0 :(得分:1)

像这样,我建议添加NC,因此不区分大小写:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^submit?$ submit.php [NC, L]
RewriteRule ^(.+)$ search.php [NC, QSA,L]

答案 1 :(得分:1)

您可以使用此:

RewriteEngine On
RewriteBase /

#rewrite /submit to /submit.php
RewriteRule ^submit/?$ submit.php [L,NC]
#rewrite other non-existent URIs to /search.pho    
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ search.php [QSA,L]