【问题标题】:.htaccess redirect from subfolder to domain not working properly.htaccess 从子文件夹重定向到域无法正常工作
【发布时间】:2021-08-11 19:42:57
【问题描述】:

我正在为我的网站使用 PHP、Laravel 8 框架和 cPanel。我正在尝试做的是这样的事情。

重定向路由
http://example.com/example.com/public/
http://example.com/example.com/public/about
http://example.com/example.com/public/contact
.
.
// more

https://example.com/
https://example.com/about
https://example.com/contact
.
.
// more

我在域根目录public_html 文件夹中有.htaccess 文件。

.htaccess 文件

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /example.com/public/$1 [L]

如果我做错了什么,请指导我。

【问题讨论】:

  • 能否请您告诉我们这些规则仅存在于您的 htaccess 文件中,还是您有更多规则?
  • 我只有这么多example.com/public文件夹我有laravel默认的htaccess文件。

标签: .htaccess redirect mod-rewrite https friendly-url


【解决方案1】:

请按照您所显示的尝试尝试以下规则。请确保在测试您的 URL 之前清除您的浏览器缓存。确保两件事。第一 - 将您的 htaccess 规则文件保存在您拥有文件夹 example.com 的同一级别,第二 - 将您的 index.php 保存在 /root/example.com/public 文件夹中。

Options -Indexes -MultiViews
RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/example\.com/public [NC]
RewriteRule ^(.*)/?$ example.com/public/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ example.com/public/index.php [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-27
    • 2018-04-06
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多