【发布时间】: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