【发布时间】:2022-01-22 06:40:27
【问题描述】:
所有带有 www (www.example.com/posts/categories) 的路径都重定向到主页。如何从 .htaccess 重定向并保留完整路径?
https://www.example.com/posts/categories to https://example.com/posts/categories
当前配置:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>
【问题讨论】:
-
您发布的规则已经这样做了。您可能与其他指令有冲突。请更新您的问题以包含完整的
.htaccess文件。