开发者

php url routing question

开发者 https://www.devze.com 2022-12-28 21:26 出处:网络
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

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 exacty开发者_开发技巧ly, 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
0

精彩评论

暂无评论...
验证码 换一张
取 消