关于apache服务器rewrite

WBOY
发布: 2016-06-23 13:38:59
原创
984 人浏览过

我的目的是在地址栏输入的url:
http://localhost/project/ShortURL/index.php/149Ui3
自动重写为
http://localhost/project/ShortURL/index.php?controller=jump&method=jemp&code=149Ui3
apache中添加配置如下(apache2.conf):

<IfModule mod_rewrite.c>     # Turn on rewrite engine     Options +FollowSymlinks     RewriteEngine on     # More rules below     RewriteRule ^index.php/(.*)$ index.php?controller=jump&method=jump&code=$1 [QSA]</IfModule>
登录后复制

但是始终不能跳转,请问应该如何正确配置呢.


回复讨论(解决方案)

1.httpd.conf中rewrite模块是否正确开启
2.你写入的这个配置文件是否有效

我在ubuntu下,没有发现httpd.conf文件,主配置文件只有apach2.conf,另外现在的配置是这样的.
1.在/var/www/project/ShortURL目录下建立一个.htaccss文件内容如下:

# Turn on rewrite engineOptions +FollowSymlinksRewriteEngine on# More rules belowRewriteRule ^index.php/(.*)$ index.php?controller=jump&method=jump&code=$1 [QSA
登录后复制

2.在apach2.conf中做了如下配置:
<Directory /var/www/project/ShortURL>    Options FollowSymLinks    AllowOverride ALL    Require all granted</Directory>
登录后复制

别的没有做配置.现在的问题是这样的:
现在问题是每次输入http://localhost/project/ShortURL/index.php/149Ui3都会显示没有css样式控制的http://localhost/project/ShortURL/index.php内容(地址栏还是http://localhost/project/ShortURL/index.php/149Ui3),不能跳转到http://localhost/project/ShortURL/index.php?controller=jump&method=jemp&code=149Ui3这个地址 

1.httpd.conf中rewrite模块是否正确开启
2.你写入的这个配置文件是否有效


现在的如#2楼所示,不好意思回复错了.

 问题解决了,总结一下:
问题描述:
我的目的是在地址栏输入的url:
http://localhost/project/ShortURL/index.php/149Ui3
自动重写为
http://localhost/project/ShortURL/index.php?controller=jump&method=jump&code=149Ui3
解决方案
1.在apach2.conf中做如下配置: 

    Options FollowSymLinks
    AllowOverride ALL
    Require all granted

2.在/var/www/project/ShortURL目录下建立一个.htaccss文件内容如下:    
# Turn on rewrite engine                                                                        
RewriteEngine on
# More rules below
RewriteBase /
RewriteRule ^index.php/(.*)$ http://localhost/project/ShortURL/index.php?controller=jump&method=j    ump&code=$1 [L,R=301]
写在最后
没事的时候还得多看文档啊,感谢开源中国疯狂的蜗牛提供的思路.

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!