Home  >  Article  >  Backend Development  >  关于apache服务器rewrite

关于apache服务器rewrite

WBOY
WBOYOriginal
2016-06-23 13:38:591023browse

我的目的是在地址栏输入的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]
写在最后
没事的时候还得多看文档啊,感谢开源中国疯狂的蜗牛提供的思路.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn