为了适应一些ajax,我正在做一个基本的.htaccess重写。
文件夹结构
main.html
alpha/
alpha.php
alpha.html
main.html包含一个用于调用 alpha/alpha 的div.php该 alpha/alpha.html 还包含 alpha .php的静态包含。
我想要一个干净的网址 www.myUrl.com/alpha 来调用 alpha/alpha.html。
如何添加 !不是一组规则的条件,所以我不必将其包含在每个规则上,例如从组中的每个规则中删除[^(html|php)]
,即
set the following condition
^[^(html|php)]$
for
RewriteRule ^(.*)_aaa$ %{DOCUMENT_ROOT}/$1/$1.html [L]
RewriteRule ^(.*)_bbb$ %{DOCUMENT_ROOT}/$1/$1.html [L]
RewriteRule ^(.*)_ccc$ %{DOCUMENT_ROOT}/$1/$1.html [L]
end condition and do not apply for
RewriteRule ^(.*)_ddd$ %{DOCUMENT_ROOT}/$1/$1.html [L]
RewriteRule ^(.*)_eee$ %{DOCUMENT_ROOT}/$1/$1.html [L]`
当前 .htaccess
Options +ExecCGIn
Options -indexes
DirectoryIndex main.html
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
# main start page
RewriteRule ^main$ main.html [L]
# clean for alpha
# myUrl.com/alpha
RewriteRule ^(.*)[^(html|php)]$ %{DOCUMENT_ROOT}/$1/$1.html [L]
谢谢艺术
尝试使用负后看:
RewriteRule ^(.*)(?<!html|php)$ %{DOCUMENT_ROOT}/$1/$1.html [L]
时髦的小(?<!html|php)$
的意思是:字符串($
)的末尾,前面没有html
或php
。
编辑:
鉴于:
set the following condition
^[^(html|php)]$
for
RewriteRule ^(.*)_aaa$ %{DOCUMENT_ROOT}/$1/$1.html [L]
RewriteRule ^(.*)_bbb$ %{DOCUMENT_ROOT}/$1/$1.html [L]
RewriteRule ^(.*)_ccc$ %{DOCUMENT_ROOT}/$1/$1.html [L]
end condition and do not apply for
RewriteRule ^(.*)_ddd$ %{DOCUMENT_ROOT}/$1/$1.html [L]
RewriteRule ^(.*)_eee$ %{DOCUMENT_ROOT}/$1/$1.html [L]`
你想要:
# If this matches, (the opposite of !(html|php)), skip all of the following rules (3 of them)
RewriteRule .(php|html)$ - [S=3]
RewriteRule ^(.*)_aaa$ %{DOCUMENT_ROOT}/$1/$1.html [L]
RewriteRule ^(.*)_bbb$ %{DOCUMENT_ROOT}/$1/$1.html [L]
RewriteRule ^(.*)_ccc$ %{DOCUMENT_ROOT}/$1/$1.html [L]
# if first condition matched, we skipped to here
RewriteRule ^(.*)_ddd$ %{DOCUMENT_ROOT}/$1/$1.html [L]
RewriteRule ^(.*)_eee$ %{DOCUMENT_ROOT}/$1/$1.html [L]`