Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

insight's avatar

How to remove /public/index.php from URL ?

Dear Friends, I am using Laravel 10 , my url is http://10.50.192.128/ksrtcCareers/public/index.php/ReceivedApplns I need to remove "/public/index.php/" part . I have no .htaccess in my root folder. So I added in root folder of /var/www/html/ksrtcCareers with content as

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

But after this too could not remove that from URL. If removed get "Not Found" . Please advise

Thanks

Anes P A

0 likes
5 replies
tykus's avatar

The .htaccess in your public directory should work - assuming you are serving the application from there?

Is mod_rewrite enabled?

insight's avatar

@tykus ``` mod_rewrite`` enabled . is .htaccess put in root directory ?

Snapey's avatar

You should change the document root of your webserver so that it serves the public folder and not your project root.

1 like
Tray2's avatar

Are you sure you are running Apache2, and not nginx?

If you are running Apache2, I suggest fir trying to change the document root in the config file for the site, if you can't try this in you .htaccess.

#Rewrite everything to subfolder 
RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/public 
Rewriterule ^(.*)$ public/ [L]
insight's avatar

I tried as per your suggestions . My current .htaccess file in /public folder is

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^(.*)$ index.php/ [L]
</IfModule>

I got apache error as

[Thu Nov 02 16:03:15.412009 2023] [core:error] [pid 206214:tid 206403] [client 10.64.241.20:55062] AH00124: Request exceeded the limit of 100 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

I added a virtualhost in /etc/httpd/conf.d/mylaravelapp.conf with content as


<VirtualHost *:80>
    ServerName 10.50.92.128
    ServerAlias *
    DocumentRoot /var/www/html/ksrtcCareers/public
    <Directory /var/www/html/ksrtcCareers/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

@tray2 I don't think your point is met my target .

This solution work for server also URL : https://www.youtube.com/watch?v=lgSmJJd3o24 ?

Please advise

Please or to participate in this conversation.