localhost.htaccess文档根目录


localhost .htaccess document root

我有一个带有简单重写规则的htaccess文件。

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?page=$1

在我的web服务器上,index.php文件位于/var/www中,并且工作正常。

在我的本地主机上,index.php-fle位于/var/www/projects/porto中,当文件正常运行时,没有加载链接的内容(图像、css等)。

我对htaccess文件完全陌生。关于如何解决这个问题,我可以在我的本地环境中进行测试,有什么想法吗?

我所尝试的只是将.htaccess文件更改为

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/?$ /running/Porto/index.php?page=$1

但运气不好。

好的,继续我们关于在本地机器/环境上设置VirtualHost的讨论,它与在其他服务器上大致相同。如果您可以从web服务器复制Apache配置文件,那么这将是一个良好的开端。至少你需要这样的东西:

<VirtualHost *:80>
    ServerName localdevsite.com
    DocumentRoot /var/www/running/Proto
</VirtualHost>

(这假设文件中的某个位置有NameVirtualHost *:80

在本地环境中,您需要做的另一件事是添加一个主机条目:

在Linux中,您通常在/etc/hosts中使用以下内容来完成此操作:

127.0.0.1 localdevsite.com