Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess doesn't work on localhost

I just started playing with URL rewriting today and I watched/read a few tutorials but I still don't really get how this rewriting works.

I created a .htaccess file and placed it in my root directory. I'm currently working on my local machine, using Apache.

I want http://localhost:5216/index.php to redirect to http://localhost:5216/index

In my .htaccess file I have the following:

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^index?$ index.php

This doesn't work. I tried refreshing the page, I checked that httpd.conf file has AllowOverride All selected. I've read a few tutorials and I think I do this the right way but it seems like I don't. What is wrong with my file?

like image 511
davidb Avatar asked Mar 02 '26 14:03

davidb


1 Answers

I faced the same problem, and my solution was this (note that I use Laragon with WAMP). It has nothing to do with invidual htaccess files, they are all ignored because of this part in Apache's httpd.conf:

DocumentRoot "D:/laragon/www"
<Directory "D:/laragon/www">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride None
    Require all granted
</Directory>

So you need to locate your httpd.conf and change AllowOverride None to AllowOverride All. Your .htaccess files should execute now.

like image 118
Balázs Varga Avatar answered Mar 04 '26 14:03

Balázs Varga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!