php url routing question

2019-06-06 23:19发布

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.

thanks

EDIT: mod rewrite is enabled

3条回答
Explosion°爆炸
2楼-- · 2019-06-06 23:59

Check if your apache installation has mod_rewrite enabled.

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

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

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

Hope that helps.

查看更多
聊天终结者
3楼-- · 2019-06-07 00:15
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
查看更多
闹够了就滚
4楼-- · 2019-06-07 00:20
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^([\d\w]+)/([\d\w]+)$ test.php?name=$1&song=$2 [L]
查看更多
登录 后发表回答