Htaccess转到文件,如果它存在否则参数

时间:2015-03-10 21:05:36

标签: .htaccess

我得到了以下htaccess

domain.com/param1/param2

domain.com/foo.php?bar=param1&baz=param2

但如果用户进入

domain.com/search

和search.php存在,我想去

domain.com/search.php

的.htaccess

IndexIgnore */*

RewriteEngine on

#RewriteCond %{HTTP_HOST} !^domain.com [NC]
#RewriteRule ^/?(.*)$ http://domain.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [L]

RewriteRule ^([a-zA-Z0-9_-]*)$ foo.php?bar=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]*)/([a-zA-Z0-9_-]*)$ foo.php?bar=$1&baz=$2 [L]

<Files .htaccess>
order allow,deny
deny from all
</Files>

1 个答案:

答案 0 :(得分:0)

您可以使用:

IndexIgnore */*

RewriteEngine on

#RewriteCond %{HTTP_HOST} !^domain.com [NC]
#RewriteRule ^/?(.*)$ http://domain.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [L]

RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^([\w-]+)/?$ foo.php?bar=$1 [L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/?$ foo.php?bar=$1&baz=$2 [L,QSA]

<Files .htaccess>
order allow,deny
deny from all
</Files>
相关问题