我正在寻找一种方法来设置我的脚本的一些设置我想要任何输入的地址在URL栏检查。htaccess,如果输入后的文本(如domain.com/foldername),然后检查和文件夹存在去文件夹如果文本与根目录下的任何文件夹都不相似,那么检查它是否有文件,最后转到特定的文件我用。htaccess:
的例子来解释一下If ( text = folder )
goes to folder
elseif( text == file )
goes to file.php
else
goes to sample.php?text
更新:我有tickets。php和theme文件夹在根目录下,我想如果url是domain.com/theme然后到名为theme文件夹和/或如果domain.com/tickets到ticket。php
像这样?
RewriteEngine On
# If ( text = folder )
RewriteRule ^folder/?$ - [L]
# if( text == file.php )
RewriteRule ^file'.php$ - [L]
# else
RewriteRule !^sample'.php /sample.php?text [L]
或者如果你指的是任何文件或文件夹:
RewriteEngine On
# If ( text = folder )
# if( text == file.php )
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# else
RewriteRule !^sample'.php /sample.php?text [L]
这是一个非常常见的模式。
此规则仅在路径不是文件夹或文件时触发。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ sample.php?path=$1 [QSA]