apache支持URL Rewrite的配置和应用
来源:互联网 发布:数据采集传输系统 编辑:程序博客网 时间:2024/06/06 06:42
最近在做php的项目要用到url rewrite的功能,由于我对于url rewrite是一片空白,所以艰难地从网上找资料学习。但是网上的资料都不是很系统,反正我单纯地看几篇文章是没弄通,只好自己慢慢总结了。
首先要让apache支持url rewrite。做法就算是在apache里面打开http.conf这个配置文件找到下面这行
#LoadModule rewrite_module modules/mod_rewrite.so
去掉前面的#。
然后让Apache支持.htaccess。在给出如何配置Apache支持.htaccess文件之前,首先申明一下:使用.htaccess文件,会降低httpd服务器的一点性能。具体做法是找到Apache的httpd.conf配置文件,找到
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
修改为
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
说明:后来经过实践证明上一步的修改不是必须的,视情况而定
找到<Directory "F:/www">,也就是你网站存放的路径,把AllowOverride None改为AllowOverride All,在后面加上Order allow,deny
Allow from all
如果存在就将#去掉。
然后在httpd.conf文件里面加上下面这段
<FilesMatch "^/.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
(也可以在文件中查找到这段代码,去掉每行前面的#,但是Satisfy All这一行可能没有,我的就没有哈)
这样就可以了。
/*
如果需要使用.htaccess以外的其他文件名,可以用AccessFileName指令来改变。
例如,需要使用.config ,则可以在服务器配置文件中按以下方法配置:
*/
AccessFileName .config
我目前只走到这一步了,下次有深入的配置再更新。
下面提供一个.htaccess文件的模版:
<FilesMatch "/.(bak|inc|lib|sh|tpl|lbi|dwt)$">
order deny,allow
deny from all
</FilesMatch>
RewriteEngine On
#RewriteBase /
# direct one-word access
RewriteRule ^index/.html$ index/.php [L]
RewriteRule ^login/.html$ login/.php [L]
RewriteRule ^suoding/.html$ minglei_suoding1/.php [L]
RewriteRule ^login_post/.html$ login_post/.php [L]
RewriteRule ^loginout/.html$ login/.php?act=logout [L]
RewriteRule ^register/.html$ register/.php [L]
RewriteRule ^phone_search/.html$ phone_search/.php [L]
RewriteRule ^zijin_list-([0-9]+)(.*)/.html$ zijin_list/.php/?page=$1 [QSA,L]
RewriteRule ^zijin_list/.html$ zijin_list/.php [L]
RewriteRule ^zijin-([0-9]+)(.*)/.html$ zijin/.php/?id=$1 [QSA,L]
- apache支持URL Rewrite的配置和应用
- nginx和apache下的url rewrite
- nginx和apache下的url rewrite
- discuz论坛Apache Rewrite实现URL重写的配置方法
- Apache Rewrite url重定向功能的简单配置
- XAPMM Apache Rewrite url重定向功能的简单配置
- Apache Rewrite url重定向功能的简单配置
- Apache Rewrite url重定向功能的简单配置
- Apache Rewrite url重定向功能的简单配置
- 配置zope的VHM和apache rewrite
- Apache Rewrite实现URL的跳转和域名跳转
- Apache Rewrite实现URL的跳转和域名跳转
- Apache Rewrite实现URL的跳转和域名跳转
- Apache Rewrite实现URL的跳转和域名跳转
- Apache Rewrite实现URL的跳转和域名跳转
- Apache Rewrite实现URL的301跳转和域名跳转
- Apache Rewrite实现URL的跳转和域名跳转
- Apache Rewrite实现URL的跳转和域名跳转
- Makefile学习笔记3:Linux下makefile基础 (zz)
- 单链表实现猴子选大王(约瑟夫环问题)
- [DirectShow] 019 - Learning When an Event Occurs
- 网站开发的需求分析报告9转载)
- 闪客工具: Allok Video to FLV Converter
- apache支持URL Rewrite的配置和应用
- 这里有一些让你养成终身学习习惯的小提示
- Petshop
- 我想学习LINUX
- Linux下端口复用(SO_REUSEADDR与SO_REUSEPORT)
- 类型转换
- 经典的C语言面试题目
- Device eth0 has different MAC address than expected
- 怎样完全卸载MySQL