1

On my domain public directory is the laravel public directory.so there is index.php and htaccess file. but i want to access mydomain.com/demo/, where demo is a folder.its always redirect me to my home page as mydomain.com because of route rewrite . so how can i access folders in mydomain.com. my htaccess is followed. ...

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

thanks in advance

Fisherman
  • 5,949
  • 1
  • 29
  • 35

3 Answers3

0

Create a separate .htaccess file within demo directory to override the .htaccess file in your root directory.

Order Allow,Deny Allow from all

Brian Dillingham
  • 9,118
  • 3
  • 28
  • 47
0

Create a separate .htaccess (as Brian Dillingham said) file within demo directory to override the .htaccess file in your root directory. But put use codes below instead:

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

Also, you can refer the answer from: https://stackoverflow.com/a/38068912

Community
  • 1
  • 1
claudchan
  • 328
  • 1
  • 2
  • 14
0

For the ones out there who use a public domain but the Laravel directory is within a subdirectory. You might have the following folder structure:

- / <-- directory your domain (e.g. "https://example.com") points to
- some_subfolder1/
- some_subfolder2/
- laravel_project/
    - ...
    - public/
        - .htaccess <-- File one has to modify
        - index.php
        - ...

The .htaccess File's RewriteRule for Front Controllers would look the following:

RewriteRule ^ laravel_project/public/index.php [L]

So you will end up with:

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

    RewriteEngine On
    RewriteBase /

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

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

In addition, I also modified the .env-File for the APP_URL param:

APP_URL=https://example.com/laravel_project/public

Furthermore, you might think of moving the laravel project files (despite from the public folder) outside of this file tree.

Lepidopteron
  • 6,056
  • 5
  • 41
  • 53