url 的 .htaccess 问题

.htaccess issue with url

这种 url 格式 https://portal.com/pages does not work but this https://portal.com/index.php/pages 有效。

我希望能够从 url 中删除 index.php。

我的根 .htaccess 文件是

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} off
  # First rewrite to HTTPS:
  # Don't put www. here. If it is already there it will be included, if not
  # the subsequent rule will catch it.
  # RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  # RewriteEngine On
  RewriteRule ^$ public/ [L]
  RewriteRule (.*) public/ [L]
  
</IfModule>

而public文件夹.htaccess文件是

<IfModule mod_rewrite.c>
  Options -Multiviews
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.+)$ index.php?url= [QSA,L]
</IfModule>

尝试遵循 htaccess 文件的规则。确保您的 index.php 存在于 public 文件夹中。请确保在测试您的网址之前清除浏览器缓存。

root htaccess 规则文件:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
  RewriteCond %{REQUEST_URI} !^/public [NC]
  RewriteRule ^(.*)/?$ public/ [L]
</IfModule>
htaccess 规则文件中的

Public 文件夹:

<IfModule mod_rewrite.c>
  RewriteOptions InheritBefore
  Options -Multiviews
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.+)/?$ index.php?url= [QSA,L]
</IfModule>

在 OP 的尝试中完成的修复:

  • root htaccess 规则文件没有 https 应用规则,所以添加了它。
  • 为所有类型的 url 制作了 public 应用规则。
  • 然后在 public 文件夹规则文件中添加 InheritBefore 选项以确保根文件被继承到 public 文件夹的 htaccess 规则文件。