apache的伪静态

vi /etc/httpd/conf/httpd.conf

<Directory "/home/www/html">

AllowOverride ALL

这个可以开启默认80端口的伪静态

 

如果在<Directory "/home/www">

AllowOverride ALL

则是开启默认8001端口的伪静态

 

开启虚拟主机的伪静态,首先在<Directory "/home/www">

AllowOverride ALL

 

vi /etc/httpd/conf.d/vhostport.conf

NameVirtualHost 10.1.1.30:80

<VirtualHost 10.1.1.30:80>   

  DocumentRoot /home/www/html

  ServerName www.gzrbs.com.cn

  <Directory "/home/www/html">

    Options Indexes FollowSymLinks

    AllowOverride all

    Require all granted

  </Directory>

</VirtualHost>

 

NameVirtualHost 10.1.1.30:8001

<VirtualHost 10.1.1.30:8001>

  DocumentRoot /home/www/hetong

  ServerName app.gzrbs.com.cn

  <Directory "/data/www">

    Options Indexes FollowSymLinks

    AllowOverride all

    Require all granted

  </Directory>

</VirtualHost>

systemctl restart httpd

 

vi /home/www/html/.htaccess 

RewriteEngine on

RewriteRule index.html index.php

 

vi /home/www/hetong/.htaccess 

RewriteEngine on

RewriteRule index.html index.php

 

访问http://10.1.1.30:80/index.html和http://10.1.1.30:8001/index.html

成功证明伪静态开启。

 

apache伪静态规则.htaccess

#表示注释后面的语句。

采用Perl的正则表达式。

RewriteRule 访问页面 实际页面

访问页面中:

^表示以其后的字符开头。

([0-9]*)代表范围,用(.*)代表所有。

$表示以其前的字符结尾。

实际页面中:

$num表示与访问页面匹配位置序号。例如$1即与访问页面中的第一个位置进行匹配。

RewriteRule ^index([0-9]*).html$ index.php?id=$1

RewriteRule ^show-([0-9]*).html$ show.php?id=$1

RewriteRule ^list-([0-9]*).html$ list.php?id=$1

 

 

访问域名app.gzrb.com的所有页面,都定向到test.php

RewriteCond %{HTTP_HOST} (app.gzrb.com)

RewriteRule (.*)$ test.php

 

把 /abc?id=123 => /test2.php?id=123 的写法:

RewriteCond %{QUERY_STRING} ^id=(.+)$ 

RewriteRule ^abc$ test2.php?id=%1 [L]

 

RewriteEngine on

 

 

http://10.1.1.101/appAPI/news-getCatePage.html?cate_id=10045

定位到

http://10.1.1.101/appAPI/index.php?act=news&op=getCatePage&cate_id=10045

的写法:

RewriteCond %{QUERY_STRING} ^cate_id=(.+)$

RewriteRule ^appAPI/news-getCatePage.html$ appAPI/index.php?cate_id=%1&act=news&op=getCatePage [L]

 

http://jgz.app.todayguizhou.com/appAPI/news-detail-news_id-11515114948432.html

定位到

http://10.1.1.101/appAPI/index.php?act=news&op=detail&news_id=11515114948432

的写法:

RewriteRule ^appAPI/([a-zA-Z]+)-([a-zA-Z]+)-([a-zA-Z]+)_id-([0-9]+).html$ appAPI/index.php?act=$1&op=$2&$3_id=$4

 

 

 

http://10.1.1.101/news/news-news_detail-news_id-11515114955279.html?preview=yes

定位到

http://10.1.1.101/news/index.php?act=news&op=news_detail&news_id=11515114955279&preview=yes

的写法:

RewriteCond %{QUERY_STRING} ^preview=yes$

RewriteRule ^news/news-news_detail-news_id-([0-9]+).html$ news/index.php?act=news&op=news_detail&news_id=$1&preview=yes [L]

 

http://10.1.1.101/news/news-news_detail-news_id-11515114955279.html

定位到

http://10.1.1.101/news/index.php?act=news&op=news_detail&news_id=11515114955279

的写法:

RewriteRule ^news/news-news_detail-news_id-([0-9]+).html$ news/index.php?act=news&op=news_detail&news_id=$1

 

 

星期一, 08/05/2019 - 16:29 — 杨超