Laravel .htaccess subfolder

送分小仙女□ 提交于 2021-02-04 08:27:07

问题


I now have a Laravel installation with the default folder structure. In my root folder I have a .htaccess file like this one.

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.

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.

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.


回答1:


So, in your root .htaccess you should use the following:

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:

RewriteBase /admin

If you can't live with the trailing slash being mandatory you can try:

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



回答2:


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


来源:https://stackoverflow.com/questions/52707058/laravel-htaccess-subfolder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!