.htaccess - htaccess 将 example.com/about 重定向到 https://www.example.com/about
问题描述
以下代码将许多请求重定向到https://www.example.com,但请求 example.com/about 会重定向到https://www.example.com。如何使其重定向到请求的页面(https://www.example.com/about)?
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://www.example.com/$1 [R,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
<Files "*.txt">
Require all denied
</Files>
</IfModule>
解决方案
It seems that you want to redirect all unavailable variation to home page, rather to relevant page or 404 page.
If it's so, then I must say it's best practice to have 404 page instead redirecting to home page.
Otherwise you can use below code for your purpose, just add below lines in your code and remove other redirections.
ErrorDocument 404 http://domainname.com
推荐阅读
- charts - 谷歌图表不工作。如何解决?
- mysql - 需要帮助编写内部连接查询
- c# - Unity+VisualStudio:C#代码反汇编不可用?
- python - 无法使用 def clean() 运行表单集验证
- gcc - Makefile - 在不同目录中编译单个对象
- c++ - 使用 Doxygen 和 GraphViz 生成工作 CHM 文件(无效的 .hhc 文件?)
- linux - 从 Windows 访问 Linux Tomcat 端口 8080
- tabs - 在 Ionic 4 中将数据从一页传递到另一页
- python - 使用动态库的机器人框架自定义关键字中的run_keyword方法中的实现问题
- c# - 无法按文件类型缩进以在 Vim 中工作