【发布时间】:2020-11-06 23:29:00
【问题描述】:
我对我的 url 处理有非常具体的要求,我不知道如何组合所有这些。
如果用户打开http://example.com/abc123,我需要进行以下更改:
-
http://应该变成https://,然后... - ...如果文件
abc123.php存在则打开https://example.com/abc123.php - ...如果目录
/abc123/存在则打开https://example.com/abc123/index.php - ...打开
https://example.com/index.php?abcdef,即使用abc123作为正常index.php的参数
对于 2. - 4. 我需要地址栏中的 url 保持https://example.com/abc123。
到目前为止,我的 .htaccess 中有以下内容,我相信它可以处理 1. 和 2.:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
【问题讨论】:
-
感谢您的详细介绍。一个问题最终来自 url
http://example.com/abc123到您想要指向后端的哪个 url?请让我们知道。 -
这取决于有哪些文件和文件夹:如果存在以下内容:example.com/abc123.php。如果不存在但存在以下内容:example.com/abc123/index.php。最后,如果两者都不存在:example.com/index.php?abcdef
标签: .htaccess url redirect mod-rewrite