htaccess 404 语言子文件夹错误 (en/)
htaccess 404 error on language subfolder (en/)
我有以下结构:
/
/about.php
/contact.php
/en/
/en/about.php
/en/contact.php
我想从 url 中删除 .php 扩展名和 www 前缀,并强制使用 https。
现在我有以下 htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ .php
RewriteRule ^([^/]+)/([^/]+)/$ //.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ // [R=301,L]
在此先感谢您的帮助!
就你所拥有的而言,你真的很接近。现在我知道了这个问题,我会告诉你我用什么——你需要一个条件,说明 不是目录 ——语法是 !-d
这就是 my htaccess 的样子(因为我用它来删除 html
以及 php
:
RewriteEngine on
# Redirect www and http to https - non-www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
# Start php extension remove
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ .php
# End php extension remove
# Start html extension remove
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ .html
# End html extension remove
如您所见,第一个 condition 检查它不是一个目录。下面的条件检查它的文件扩展名是否是.php
。如果两个条件都是 true -- rule 是删除扩展。
请注意——我会让您的语法更简洁一些,并将您尝试执行的操作的 "sections" 分开。
根据评论更新
要删除 https
强制 - 只需注释掉第一个 条件 并将 [=31] 中的 https
更改为 http
=]规则:
RewriteEngine on
# Redirect www and http to https - non-www
#RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Start php extension remove
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ .php
# End php extension remove
# Start html extension remove
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ .html
# End html extension remove
我有以下结构:
/
/about.php
/contact.php
/en/
/en/about.php
/en/contact.php
我想从 url 中删除 .php 扩展名和 www 前缀,并强制使用 https。
现在我有以下 htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ .php
RewriteRule ^([^/]+)/([^/]+)/$ //.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ // [R=301,L]
在此先感谢您的帮助!
就你所拥有的而言,你真的很接近。现在我知道了这个问题,我会告诉你我用什么——你需要一个条件,说明 不是目录 ——语法是 !-d
这就是 my htaccess 的样子(因为我用它来删除 html
以及 php
:
RewriteEngine on
# Redirect www and http to https - non-www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
# Start php extension remove
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ .php
# End php extension remove
# Start html extension remove
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ .html
# End html extension remove
如您所见,第一个 condition 检查它不是一个目录。下面的条件检查它的文件扩展名是否是.php
。如果两个条件都是 true -- rule 是删除扩展。
请注意——我会让您的语法更简洁一些,并将您尝试执行的操作的 "sections" 分开。
根据评论更新
要删除 https
强制 - 只需注释掉第一个 条件 并将 [=31] 中的 https
更改为 http
=]规则:
RewriteEngine on
# Redirect www and http to https - non-www
#RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Start php extension remove
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ .php
# End php extension remove
# Start html extension remove
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ .html
# End html extension remove