简体   繁体   English

Laravel .htaccess 子文件夹

[英]Laravel .htaccess subfolder

I now have a Laravel installation with the default folder structure.我现在有一个具有默认文件夹结构的 Laravel 安装。 In my root folder I have a .htaccess file like this one.在我的根文件夹中,我有一个像这样的 .htaccess 文件。

Options +FollowSymLinks

<IfModule mod_rewrite.c>

    # RewriteEngine On
    # RewriteCond %{REQUEST_FILENAME} !-d
    # RewriteCond %{REQUEST_FILENAME} !-f
    # RewriteRule ^ index.php [L]

    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]

</IfModule>

I have to install in a subfolder WordPress.我必须安装在子文件夹 WordPress 中。

So I would like to access to my WP installation using the URL http://www.example.com/ and to Laravel with http://www.example.com/admin .所以我会使用URL喜欢访问我的WP安装http://www.example.com/和Laravel与http://www.example.com/admin

The thing I know it's that is an .htaccess trick, but, even if I tried many kind of rewrites, I'm not still able to achieve the desired result.我知道这是一个 .htaccess 技巧,但是,即使我尝试了多种重写,我仍然无法达到预期的结果。

So, in your root .htaccess you should use the following:因此,在您的根.htaccess您应该使用以下内容:

RewriteEngine On

# Route any request begining with 'admin/' to laravel
RewriteRule ^admin/(.*)$ public/$1 [L]
# Anything else goes to Wordpress
RewriteRule ^(.*)$ wp/$1

And in your Laravel .htaccess add:在你的 Laravel .htaccess添加:

RewriteBase /admin

If you can't live with the trailing slash being mandatory you can try:如果您不能接受强制使用尾随斜杠,您可以尝试:

RewriteRule ^admin(/(.*))?$ public/$2 [L]

Try this:尝试这个:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /your-subdirectory/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /your-subdirectory/index.php [L]
</IfModule>

# END WordPress

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM