Hello,

I am having a problem with .htaccess file here. I am having a program written with laravel and whatever /... I write change into localhost/dashboard.

Someone mention I need to change the .htaccess file but I do not know how to. If anyone here can help me please do so. Here is my

.htaccess

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

   RewriteEngine On

   RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

   # 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 ^ index.php [L]
  </IfModule>

Dani AI

Generated

Likely cause: Apache is serving the server's default document root (the dashboard) instead of the Laravel app, or Apache is ignoring the Laravel .htaccess so routes never reach index.php. 's suggestion to comment the rewrite rules is a useful quick test, but a few targeted checks will find the real problem faster.

Quick checklist and diagnostics:

  • Verify the app itself: run Laravel's dev server to confirm routes work standalone.
  • Confirm the Laravel .htaccess lives in the public/ folder and is readable by the webserver.
  • Make sure mod_rewrite is enabled and the Apache vhost (or directory) allows .htaccess usage (AllowOverride All).
  • Look at Apache error logs for rewrite or permission errors.

Quick commands (examples):

php artisan serve
apachectl -M | grep rewrite        # or: httpd -M | findstr rewrite on Windows
sudo a2enmod rewrite && sudo systemctl restart apache2

If the built-in server serves /admin correctly, Apache is the issue. The clean fix is a virtual host that points the DocumentRoot to Laravel's public directory. Example vhost:

<VirtualHost *:80>
    ServerName myapp.test
    DocumentRoot "/full/path/to/laravel/public"
    <Directory "/full/path/to/laravel/public">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Also add 127.0.0.1 myapp.test to the hosts file for local name testing.

Notes and cautions: never point DocumentRoot at the project root (keep only public web-accessible), clear Laravel caches if needed (php artisan config:clear / route:clear), and check for any Apache Alias (XAMPP ships a dashboard alias) that could conflict with the desired URL. For , if the built-in server shows the admin login then focus configuration on the Apache vhost/AllowOverride; if it does not, check routes/middleware/auth in Laravel.

Recommended Answers

All 3 Replies

Hi davy,

the .htaccess seems to be fine, so I have some questions for you:

  • which web server are you using?
  • Are you using a virtual host config?
  • Which is the document root?
  • What do you expect to get instead of http://localhost/dashboard ?

Right now, the document root is localhost.

I try to type /admin and expect the admin page to ask me to input login and password yet it does not appears.

I don't know the web server name - yet it appears just like the other web server.

A virtual host config? I'm not quite sure about this.

Comment the rules in the .htaccess file and try again to access /admin. If you get redirected post the code of /admin.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.