首先,我道歉。这个话题已经被反复讨论,(我知道。我读过它们。)但无论出于何种原因,我的情况要么很奇怪,要么我在 .htaccess 中破坏了其他东西。
客观的
隐藏 PHP 文件扩展名,
第301话
允许实际引用子目录中的 PHP 文件,
将文件名中的下划线重写为斜杠 (/),使它们看起来是嵌套的。(编辑:或将 URL 中的 / 翻译为文件中的 _'s - 除非该目录存在。)
... 3 & 4 是踢球者。
以下代码是我在此之前一直使用的 .htaccess...
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
## Imagine Some Code here ##
# Redirect to domain with www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Ensure all directory URLs have a trailing slash.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\/$
RewriteCond %{REQUEST_URI} !\/[^\/]*\.[^\/]+$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
# Same for HTTPS:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\/$
RewriteCond %{REQUEST_URI} !\/[^\/]*\.[^\/]+$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
</IfModule>
我尝试在我注意到的地方添加以下片段。
RewriteRule ^$ /index.php [L]
RewriteRule ^([a-zA-Z0-9\-\_/]*)/$ /$1/index.php [L]
RewriteRule ^([a-zA-Z0-9\-\_/]*)\.(html|htm)$ /$1.php [L]
RewriteRule ^([a-zA-Z0-9\-\_/]*)$ /$1.php [L]
和
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
最成功的是:
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ https://www.actual_domain.com.au/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ https://www.actual_domain.com.au/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
最后一个实际上非常好,但是,我根本无法访问子目录中任何格式(带/不带扩展名)的 php 文件。并且所有尝试添加处理需求 4 的东西都没有奏效。
尽管我很希望有人去 BAM,完成。使用和享受。我也很想知道出了什么问题。
提前致谢。