我想在我的根目录的子目录中有3个文件夹。
我的网站地图:
mywebsite.com
mywebsite.com/test/
mywebsite.com/test/one/
mywebsite.com/test/one/one.php
mywebsite.com/test/two/two.php
mywebsite.com/test/three/three.php
我想访问:
mywebsite.com/test/one/one.php
mywebsite.com/test/two/two.php
mywebsite.com/test/three/three.php
使用:
mywebsite.com/test/combine/one.php
mywebsite.com/test/combine/two.php
mywebsite.com/test/combine/three.php
RewriteEngine On
RewriteRule .* - [E=directory:/test/]
RewriteRule .* - [E=one:one/]
RewriteRule .* - [E=two:two/]
RewriteRule .* - [E=three:three/]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:one}$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:one}$1 -d
RewriteRule ^combine/(.*)$ %{ENV:directory}%{ENV:one}$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:two}$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:two}$1 -d
RewriteRule ^combine/(.*)$ %{ENV:directory}%{ENV:two}$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:three}$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:three}$1 -d
RewriteRule ^combine/(.*)$ %{ENV:directory}%{ENV:three}$1 [L]
这有效,但我想最小化脚本
答案 0 :(得分:1)
如果您简化它,请尝试以这种方式进行整合。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/test/$1/$1.php -f
RewriteRule ^combine/(.*)(?:\.php)$ /test/$1/$1.php [L]