简体   繁体   中英

php url routing question

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM