如何重写现有的重写路径?
How to rewrite for existing rewrite path?
我的 .htaccess 文件中有这段代码,可以重定向转到 www.example.com/inventory/anySKUnumber:
的用户
RewriteEngine On
# Change URL to .../inventory/$row[number]
RewriteRule ^Inventory/([^/]*)$ /Inventory/vendors/php/LandingPage/DirectSKU.php?number= [QSA,L,NC]
现在我也想要,如果用户转到 www.example.com/inventory 他们会被重定向到主页,但我想在地址栏中保持相同的路径 [而不仅仅是重定向到它]。
尝试此操作时,我被重定向但地址栏中的路径为空:
RewriteEngine On
# Change URL to .../inventory/$row[number]
RewriteRule ^Inventory/([^/]*)$ /Inventory/vendors/php/LandingPage/DirectSKU.php?number= [QSA,L,NC]
# Redirect to index but keep path
RewriteRule ^Inventory/?$ /$ [QSA,NC]
如何在保持路径 (http://www.example.com/inventory) 的同时进行重定向?
在第一个重写规则中使用了星号。星号可以匹配零个字符,这是不需要的。使用加号可以解决问题。这是完整的代码:
RewriteEngine On
RewriteBase /
# Change URL to .../Inventory/$row[number]
RewriteRule ^Inventory/([^/]+)$ /vendors/pages/Inventory/LandingPage/DirectSKU.php?number= [QSA,L,NC]
# Redirect to index but keep paths
RewriteRule ^Inventory/?$ index.php [QSA,NC]
我的 .htaccess 文件中有这段代码,可以重定向转到 www.example.com/inventory/anySKUnumber:
的用户RewriteEngine On
# Change URL to .../inventory/$row[number]
RewriteRule ^Inventory/([^/]*)$ /Inventory/vendors/php/LandingPage/DirectSKU.php?number= [QSA,L,NC]
现在我也想要,如果用户转到 www.example.com/inventory 他们会被重定向到主页,但我想在地址栏中保持相同的路径 [而不仅仅是重定向到它]。
尝试此操作时,我被重定向但地址栏中的路径为空:
RewriteEngine On
# Change URL to .../inventory/$row[number]
RewriteRule ^Inventory/([^/]*)$ /Inventory/vendors/php/LandingPage/DirectSKU.php?number= [QSA,L,NC]
# Redirect to index but keep path
RewriteRule ^Inventory/?$ /$ [QSA,NC]
如何在保持路径 (http://www.example.com/inventory) 的同时进行重定向?
在第一个重写规则中使用了星号。星号可以匹配零个字符,这是不需要的。使用加号可以解决问题。这是完整的代码:
RewriteEngine On
RewriteBase /
# Change URL to .../Inventory/$row[number]
RewriteRule ^Inventory/([^/]+)$ /vendors/pages/Inventory/LandingPage/DirectSKU.php?number= [QSA,L,NC]
# Redirect to index but keep paths
RewriteRule ^Inventory/?$ index.php [QSA,NC]