Heim  >  Artikel  >  Backend-Entwicklung  >  关于apache服务器rewrite

关于apache服务器rewrite

WBOY
WBOYOriginal
2016-06-23 13:38:59985Durchsuche

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn