Emanuele Coppola
Emanuele Coppola

Reputation: 304

Laravel .htaccess subfolder

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.

Upvotes: 0

Views: 14561

Answers (2)

msg
msg

Reputation: 8171

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]

Upvotes: 3

Ramesh Navi
Ramesh Navi

Reputation: 773

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

Upvotes: 0

Related Questions