SA__
SA__

Reputation: 1862

Adding 'public/index.php' to all requests without changing url

I want to add public/index.php to all request using .htaccess

I tried like this

RewriteEngine on
RewriteRule ^/(.*)$ /public/index.php/$1 [NC,L]

but it didn't changed ..

Example :

If i type

localhost/project/first

it should request

localhost/project/public/index.php/first

What is the issue in my .htaccess ?

Upvotes: 0

Views: 54

Answers (1)

anubhava
anubhava

Reputation: 784998

You can use a rule like this in /project/.htaccess:

RewriteEngine On
RewriteBase /project/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/index.php/$1 [L]

And this is /project/public/.htaccess:

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

RewriteEngine On
RewriteBase /project/public/

RewriteRule index\.php$ - [L,NC]

# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [L,R=301,NE]

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

RewriteCond are required to avoid rewriting for real files and directories. And There shouldn't be any leading slash in RewriteRule pattern in .htaccess. .htaccess is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule URI pattern.

Upvotes: 1

Related Questions