在将远程服务器升级到Ubuntu 14.04(Apache 2.4)之后,我无法使用以前的格式来请求URI,而无需像在CodeIgniter这样的框架中调用文件扩展名。
当我打电话http://example.com/about我打电话about.php。 这在Ubuntu 12.04工作,但现在没有find页面。
这仍然适用于我的本地机器仍然是12.04,所以我不认为这是一个.htaccess的问题,我也不相信它是一个网站可用的文件问题。 此外,这是版本控制使用GIT所以一切都几乎相同,除了一些调用站点名称和文件path的variables。 –CORRECTION:这是一个.conf的问题,如下面在我的更新中所述。
我有a2enmod(mode_rewrite)。
但要完成,我将提供htaccess和站点可用文件;
/etc/apache2/sites-avaialable/example.net.conf:
<VirtualHost xxx.xxx.xxx.xxx:443> SSLEngine On SSLCertificateFile /etc/apache2/ssl/domains/example.net/example.pem SSLCertificateKeyFile /etc/apache2/ssl/domains/example.net/example.key ServerAdmin [email protected] ServerName example.net DirectoryIndex index.php index.html DocumentRoot /var/www/html/example.net/www/ <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/html/example.net/www> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> # Log file locations LogLevel warn ErrorLog /var/www/html/example.net/logs/error.log CustomLog /var/www/html/example.net/logs/access.log combined </VirtualHost> <VirtualHost *:80> # Admin email, Server Name (domain name), and any aliases ServerAdmin [email protected] ServerName example.net ServerAlias www.example.net # Index file and Document Root (where the public files are located) DirectoryIndex index.php index.html DocumentRoot /var/www/html/example.net/www/ <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/html/example.net/www> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> # Log file locations LogLevel warn ErrorLog /var/www/html/example.net/logs/error.log CustomLog /var/www/html/example.net/logs/access.log combined </VirtualHost>
END example.net.conf
我应该注意到,在我的本地机器中,扩展less的URI调用成功了。
更新:
我已经删除了代码到我的.htaccess文件,因为我决定不再使用它,因为它是不必要的,并减慢服务器。
我目前在(80和443)VirtualHost指令底部的example.net.conf文件中有这样的设置:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php
这在一定程度上起作用。 我遇到的问题是导航到文档根目录 – > example.com,现在只显示所有文件和目录的索引而不是内容。
问题在于.conf文件(或.htaccess,如果你使用的话)。
我有我的.conf文件中的以下内容:
<IfModule mod_rewrite.c> Options +FollowSymLinks -MultiViews RewriteEngine on RewriteCond %{REQUEST_URI} !-d RewriteCond %{REQUEST_URI}\.php -f RewriteRule ^(.*)$ $1.php [L] </IfModule>
我终于明白,从Apache 2.2开始,您必须预先安装DOCUMENT_ROOT。 所以下面现在的作品:
<IfModule mod_rewrite.c> Options +FollowSymLinks -MultiViews RewriteEngine on RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f RewriteRule ^(.*)$ $1.php [L] </IfModule>
我创build了一个configuration示例,能够执行没有.php扩展名的/ testclass / testmethod
对于重写规则,我遵循codeigniter的指导原则