linux Ubuntu apache2 伪静态设置

Ubuntu Apache 伪静态配置 url重写 步骤:
1.加载rewrite模块
sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

2.将您的主机的<Directory></Directory>中的AllowOverride None改为AllowOverride All (我这边是/etc/apache2/apache2.conf)

3.在你的网站的目录下建立.htaccess文件
并建立如下内容
RewriteEngine on

(在这个地方如果报

[Sat Jan 24 07:51:53.568313 2015] [core:alert] [pid 1043] [client 101.130.216.102:51423] /var/www/html/.htaccess: Invalid command ‘ewriteEngine‘, perhaps misspelled or defined by a module not included in the server configuration错误,很可能是因为拼写错误,我在第一次配置的时候把RewriteEngine on写成了ewriteEngine on

报错的话可以 vim /var/log/apache2/error.log

查看)
RewriteBase   /
RewriteRule ^(.*)show-([0-9]+)-([0-9]+)\.html$ $1/show.php?itemid=$2&page=$3

其中RewriteRule是例子,意思为在浏览器中输入的是show-1-2.html,而实际访问的却是show.php?itemid=1&page=2


4.重启apache2

5.测试

在show.php 输入

<?php 
echo $_GET[‘itemid‘].$_GET[‘page‘];
?>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。