0

为了适应一些 ajax,我正在进行基本的 .htaccess 重写。

文件夹结构

main.html
alpha/
      alpha.php
      alpha.html

main.html 包含一个调用 alpha/alpha.php 的 div,alpha/alpha.html 还包含 alpha.php 的静态包含。

我想要一个调用 alpha/alpha.html 的干净 url www.myUrl.com/alpha。

如何为一组规则添加一个 !NOT 条件,这样我就不必在每个规则上都包含它,例如[^(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] 

谢谢艺术

4

1 回答 1

0

尝试使用消极的后视:

RewriteRule ^(.*)(?<!html|php)$ %{DOCUMENT_ROOT}/$1/$1.html [L] 

时髦的小意思(?<!html|php)$是:字符串 ( $)的结尾没有ahtmlphp


编辑:

鉴于:

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]`
于 2012-10-03T08:46:07.357 回答