PHP的URL路由问题 [英] php url routing question

查看:62
本文介绍了PHP的URL路由问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://mysite.com/songs/company-name/song-name

我想将其重定向到

http://mysite.com/songs/index.php?name=company-name&song=song-name

我读了一些有关该mod_rewrite的文章,但实际上我无法完全理解,如果您能帮助我,我将不胜感激.

i read some articles about that mod_rewrite but actually i couldnt understand exactyly, i appreciate if you can help me.

谢谢

启用了mod重写

推荐答案

检查您的apache安装是否启用了mod_rewrite.

Check if your apache installation has mod_rewrite enabled.

以最简单的形式,完成您想做的事情的规则是:

In its simplest form, the rule to accomplish what you want to do would be:

在您的.htaccess中

In your .htaccess

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^/?$ http://mysite.com [R=301,L]

RewriteRule songs/(.*)/(.*)$ songs/index.php?name=$1&song=$2

但是请仔细阅读apache文档 http://httpd. apache.org/docs/1.3/mod/mod_rewrite.html 并验证您的配置,在这里您还可以找到一些有用的信息

But give it a read to the apache documentation http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html as well as verify your configuration, and here you'd find some useful stuff as well http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/#redirects

希望有帮助.

这篇关于PHP的URL路由问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆