在ubuntu服务器中为php

时间:2016-04-04 05:16:33

标签: php apache .htaccess ubuntu mod-rewrite

我在ubuntu服务器上有我的文件。我的项目中有一个.htaccess文件。我无法在服务器中访问该文件。我想在我的服务器中启用.htaccess文件。怎么办?

这是我在/var/www/html/.htaccess

中的代码
RewriteEngine on

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php

请帮忙。

1 个答案:

答案 0 :(得分:3)

启用.htaccess(mod_rewrite)

登录SSH并执行以下操作,

john@doe:~$  sudo a2enmod rewrite
john@doe:~$  sudo service apache2 reload

通常这是在Ubuntu中启用重写模块的方式。

通过终端查看和编辑隐藏文件。

john@doe:~$  cd /var/www/html/your_website_root/
john@doe:~$  ls -la # this command will display all files including hidden files.
john@doe:~$  vi .htaccess # to edit the htaccess file

您可以使用vi,vim和nano等来通过终端编辑文件。

如果仍然无法使用htaccess,请在虚拟主机条目中进行以下更改。

更改

Options Indexes FollowSymLinks MultiViews

Options Indexes FollowSymLinks

我希望这会有所帮助。