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'];
?>

posted on 2015-01-24 08:08  叶落空山  阅读(754)  评论(0编辑  收藏  举报