0

我正在尝试使用 htaccess 中的重写器将 2 个单独的虚拟目录重定向到文件

一个虚拟目录是admin并且应该重定向到admin.php

http://dev.int/shop/admin>http://dev.int/shop/admin.php/

http://dev.int/shop/admin/>http://dev.int/shop/admin.php/

http://dev.int/shop/admin/products>http://dev.int/shop/admin.php/products

http://dev.int/shop/admin/products/add>http://dev.int/shop/admin.php/products/add

第二个虚拟目录是其他任何东西,应该重定向到index.php

http://dev.int/shop/anything>http://dev.int/shop/index.php/anything

http://dev.int/shop/anything/else>http://dev.int/shop/index.php/anything/else

还有一些其他标准,目录assets_test文件robots.txtsitemap.xml应该被重定向

这是我到目前为止所拥有的,但它不起作用:(

RewriteEngine on
RewriteCond $1 !^(assets|_test)
RewriteCond $1 !^(index\.php|admin\.php|robots\.txt|sitemap\.xml)
RewriteRule ^admin/?(.*)$ /shop/admin.php/$1 [L]
RewriteRule ^(?:admin)/?(.*)$ /shop/index.php/$1 [L]
4

2 回答 2

1

You may try this:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

# "admin" string is present
RewriteCond %{REQUEST_URI} !(assets|_test|robots\.txt|sitemap\.xml)  [NC]
RewriteCond %{REQUEST_URI}  ^/shop/admin(.*)?/? [NC]
RewriteCond %{REQUEST_URI} !admin\.php          [NC]
RewriteRule .              shop/admin.php%1     [R=301,L]

# "admin" string is NOT present
RewriteCond %{REQUEST_URI} !(assets|_test|robots\.txt|sitemap\.xml|admin)  [NC]
RewriteCond %{REQUEST_URI}  ^/shop(.*)?/?       [NC]
RewriteCond %{REQUEST_URI} !index\.php          [NC]
RewriteRule .              shop/index.php%1     [R=301,L]

When admin string is present after the /shop/ folder, redirects permanently:

http://dev.int/shop/admin/any/number/of/folders with or without trailing slash.

To:

http://dev.int/shop/admin.php/any/number/of/folders

Replacing admin with admin.php in the path stream without any other modification.


When admin string is NOT present at all, redirects permanently:

http://dev.int/shop/any/number/of/folders with or without trailing slash.

To:

http://dev.int/shop/index.php/any/number/of/folders

Inserting index.php after the /shop/ folder in the path stream without any other modification.


None of the above rules is applied when the incoming URL contains:

assets, _test, robots.txt or sitemap.xml in the path stream.

For silent mapping, remove R=301 from [R=301,L].

于 2013-02-10T00:25:24.200 回答
0

感谢@faa 的支持和指导。以下是工作答案。

RewriteEngine On

# backend
RewriteCond $1 !^(\.php)  [NC]
RewriteRule ^admin(.*)$ /itmanx/shop/draytek/admin.php$1 [R=301,L]

# frontend
RewriteCond $1 !^(index\.php|admin|assets|__test|robots\.txt|sitemap\.xml)  [NC]
RewriteRule ^(.*)$ /itmanx/shop/draytek/index.php/$1 [R=301,L]
于 2013-02-10T09:32:50.920 回答