简体   繁体   English

Apache mod_rewrite将链接重定向到localhost。 如何使.htaccess与本地计算机中的每个站点一起使用?

[英]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. 我已经将Xampp安装为Web服务器,并希望为我的一个项目创建干净的URL。 So I put these simple lines in .htaccess file in the root of this project: 因此,我将这些简单的行放在此项目根目录的.htaccess文件中:

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. 我希望去localhost / this_project / about / ,但是不起作用。 I go to localhost/about/ and this is wrong. 我去localhost / about / ,这是错误的。 How can I solve this problem? 我怎么解决这个问题?

I also have put this line in the 2nd line of .htaccess file, but no change happened. 我还将这一行放在.htaccess文件的第二行中,但是没有发生任何变化。

RewriteBase /this_project/

Attention: There are many directories in htdocs folder for each project. 注意:每个项目的htdocs文件夹中都有许多目录。

You htaccess looks OK so I guess you are missing 您的htaccess看起来还不错,所以我想您不见了

AllowOverride All

In the VHOST <directory> block. 在VHOST <directory>块中。 If you server will fail after you add AllowOverride make sure you enabled mod_rewrite. 如果在添加AllowOverride之后服务器将失败,请确保启用了mod_rewrite。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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