【问题标题】:Laravel 2 different htaccess RewriteRule ProblemLaravel 2 不同的 htaccess RewriteRule 问题
【发布时间】:2022-02-03 22:30:46
【问题描述】:

在我们使用 Laravel 的项目中,我们想要一个特定的 url 来运行另一个 php 文件。但是我们要的url是不断的进入Laravel。我们无法更改项目的 DocumentRoot,因此我们有 2 个不同的 .htaccess 文件。

当请求到达 api/v1/user/donate 时,我们想要运行 /home/userName/project/subdomains/client/user.php。我们该怎么做?

项目根目录:/home/userName/public_html

项目根.htaccess文件内容;

<IfModule mod_rewrite.c>
# That was ONLY to protect you from 500 errors
# if your server did not have mod_rewrite enabled

RewriteEngine On
# RewriteBase /
# NOT needed unless you're using mod_alias to redirect

RewriteCond %{REQUEST_URI} !/public
RewriteRule ^(.*)$ public/$1 [L]
# Direct all requests to /public folder
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php80” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php80 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

项目的公用文件夹.htaccess文件内容;

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

我们对两个 .htaccess 文件都使用了这个规则,但它不起作用;

RewriteRule ^api/v1/user/donate$ /subdomains/client/user.php [L,QSA]

【问题讨论】:

  • 你在这些文件中的哪里尝试过这个?在第一个没有多大意义,恕我直言,在第二个中,它当然必须在 对 index.php 进行一般重写之前进行

标签: php laravel apache .htaccess


【解决方案1】:

试试:

Alias "/api/v1/user/donate" "/home/userName/project/subdomains/client/user.php"

【讨论】:

  • 我们不能使用 apache 配置。我们可以只使用 .htaccess
  • @BurakErikan 如果无法访问 apache 配置,您将无法实现这一目标
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-09
  • 2014-07-04
  • 2016-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多