[英]php url routing question
http://mysite.com/songs/company-name/song-name http://mysite.com/songs/company-name/song-name
i want to redirect it to 我想将其重定向到
http://mysite.com/songs/index.php?name=company-name&song=song-name
i read some articles about that mod_rewrite but actually i couldnt understand exactyly, i appreciate if you can help me. 我读了一些有关mod_rewrite的文章,但实际上我无法完全理解,如果您能帮助我,我将不胜感激。
thanks 谢谢
EDIT: mod rewrite is enabled 编辑:mod重写已启用
Check if your apache installation has mod_rewrite enabled. 检查您的apache安装是否启用了mod_rewrite。
In its simplest form, the rule to accomplish what you want to do would be: 以其最简单的形式,完成您想要做的事情的规则是:
In your .htaccess 在您的.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
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 但是,请仔细阅读apache文档http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html并验证您的配置,在这里您还会发现一些有用的东西http:// perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/#redirects
Hope that helps. 希望能有所帮助。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\d\w]+)/([\d\w]+)$ test.php?name=$1&song=$2 [L]
RewriteEngine On
RewriteRule ^/songs/([\d\w\-]+)/([\d\w\-]+)$ test.php?name=$1&song=$2 [L]
Sometimes it helps to have logging turned on: 有时打开日志记录会有所帮助:
RewriteLogLevel 4
RewriteLog /home/www/mysite.com/log/rewrite.log
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.