简体   繁体   中英

Apache mod_rewrite redirects links to localhost. How to make .htaccess to work with each site in local machine?

I've installed Xampp as a web server and want to make clean URLs for one of my projects. So I put these simple lines in .htaccess file in the root of this project:

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

Also I made links in this project like this:

<a href="/about/">About Us</a>

I expected to go to localhost/this_project/about/ , but it does not work. I go to localhost/about/ and this is wrong. How can I solve this problem?

I also have put this line in the 2nd line of .htaccess file, but no change happened.

RewriteBase /this_project/

Attention: There are many directories in htdocs folder for each project.

You htaccess looks OK so I guess you are missing

AllowOverride All

In the VHOST <directory> block. If you server will fail after you add AllowOverride make sure you enabled mod_rewrite.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM