ear*_*son 2 url-routing apache-2.4 ubuntu-14.04
将远程服务器升级到 Ubuntu 14.04 (Apache 2.4) 后,我无法使用以前的格式来请求 URI,而无需调用文件扩展名,就像在 CodeIgniter 等框架中调用页面的方式一样。
当我调用http://example.com/about时,我调用的是 about.php。这在 Ubuntu 12.04 中有效,但现在找不到页面。
这仍然适用于我的本地机器,它仍然是 12.04,所以我不认为这是 .htaccess 问题,也不认为这是站点可用的文件问题。此外,这是使用 git 控制的版本,所以除了几个调用站点名称和文件路径的 Vars 之外,一切都几乎相同。--更正:这是一个 .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 webmaster@example.net
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 webmaster@example.net
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>
Run Code Online (Sandbox Code Playgroud)
结束example.net.conf
我应该注意,这在我的本地机器中是相同的,其中无扩展名的 URI 调用成功。
更新:
我已将代码删除到我的 .htaccess 文件中,因为我决定不再使用它,因为它是不必要的并且会减慢服务器的速度。
我目前在我的 example.net.conf 文件中(80 和 443)VirtualHost 指令的底部设置了这个:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Run Code Online (Sandbox Code Playgroud)
这在某种程度上有效。我遇到的问题是导航到文档根目录-> 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>
Run Code Online (Sandbox Code Playgroud)
我终于了解到,从 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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7495 次 |
最近记录: |