如果是文档,则最后一个路径名重定向到第一个路径名

Last pathname redirecting to first pathname if it's a document

假设我有一个名为 contact.php 的文档;我注意到出于某种原因,当我将这样的字符串放入 URL 栏时,我总是被重定向到初始文档(如果存在):

https://www.website.com/contact/pathname2

但是如果 URL 是这样的,它会转到错误 300 页面(预期行为):

https://www.website.com/Contact/pathname2

如何在不区分大小写的情况下为两个 URL 条目获得相同的 [预期行为] 结果?除非该页面存在(请参阅下面的 .htaccess 代码的第 18 行)

这是我放入 .htaccess 的内容

RewriteEngine On
RewriteBase /

RewriteCond %{SERVER_PORT} 80

CheckSpelling On

# Always https
RewriteRule ^(.*)$ https://www.website.com/ [R,L]

# Redirect pages
RewriteRule ^Home/?$ index.php [QSA,NC]
RewriteRule ^Inventory/?$ inventory.php [QSA,NC]
RewriteRule ^Shows/?$ shows.php [QSA,NC]
RewriteRule ^Contact/?$ contact.php [QSA,NC]

# Change URL to .../Inventory/SKU(number)
RewriteRule ^Inventory/([^/]+)/?$ /vendors/pages/Inventory/LandingPage/DirectSKU.php?number= [QSA,L,NC]

# Check if page has error
ErrorDocument 300 /vendors/pages/error.php
ErrorDocument 400 /vendors/pages/error.php
ErrorDocument 401 /vendors/pages/error.php
ErrorDocument 403 /vendors/pages/error.php
ErrorDocument 404 /vendors/pages/error.php
ErrorDocument 500 /vendors/pages/error.php

根据您显示的 attempted/rules,您能否尝试遵循规则文件。请确保在测试您的 URL 之前清除您的浏览器缓存。您的规则看起来像以 Contact(不区分大小写)结尾的确切 URL,因此它不会在 URI 中的 Contact 之后选择任何内容。此外,您还没有使用 L 标志,因此一旦找到匹配条件就必须使用它来停止它。

Options -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{SERVER_PORT} 80

CheckSpelling On

# Always https
RewriteRule ^ https://www.website.com%{REQUEST_URI} [NE,R=301,L]

# Redirect pages
RewriteRule ^Home index.php [QSA,NC,L]
RewriteRule ^Inventory inventory.php [QSA,NC,L]
RewriteRule ^Shows shows.php [QSA,NC,L]
RewriteRule ^Contact contact.php [QSA,NC,L]

# Change URL to .../Inventory/SKU(number)
RewriteRule ^Inventory/([^/]+)/?$ /vendors/pages/Inventory/LandingPage/DirectSKU.php?number= [QSA,L,NC]

# Check if page has error
ErrorDocument 300 /vendors/pages/error.php
ErrorDocument 400 /vendors/pages/error.php
ErrorDocument 401 /vendors/pages/error.php
ErrorDocument 403 /vendors/pages/error.php
ErrorDocument 404 /vendors/pages/error.php
ErrorDocument 500 /vendors/pages/error.php