duan32342 2013-12-02 22:20
浏览 34
已采纳

Mod_rewrite,除了引用另一个规则

i want to use mod_rewrite on my page and already have some rules

now i want to redirect to artist.php?name=(PARAMETER) except it matches another rule

at the moment i use a "a/" before artist.php because i dont know how to solve this problem so if i want so see the artist "Alex" ist just have to type domain.com/Alex and if i want to go to the about page i just have to type domain.com/about (just like facebook or twitter)

of course i'm thankfully for each improvement

Here is the .htaccess

    RewriteEngine On 
RewriteBase / 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule ^cover/([0-9]*)(s|m)?\.jpg$ /cover.php?id=$1&size=$2
RewriteRule ^dl/([^/]*)/([^/]*)$ /download.php?$1=$2
RewriteRule ^track/([^/]*)\.mp3$ /song.php?id=$1
RewriteRule ^my(/)([^/]*)$ /my.php?requested=$2
RewriteRule ^album/(.*)-([0-9]{0,6})$ /album.php?id=$2
RewriteRule ^a/([^/]*)$ /artist.php?name=$1
RewriteRule ^a/([^/]*)/music$ /music.php?name=$1
RewriteRule ^(artists|about|charts|contact|myprofile|editprofile|mymusic|uploadsongs|logout|genres)$ /$1.php
RewriteRule ^t$ /t.php
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com(/)?.*$ [NC]
RewriteRule .*\.(mp3)$ - [F,NC]

ErrorDocument 404 /errors/404.php

p.s.: i'm sorry for my bad english

  • 写回答

1条回答 默认 最新

  • douxun4173 2013-12-02 22:30
    关注

    You need to rearrange some of your rules, and add L flags so they don't accidentally get applied:

    RewriteEngine On 
    RewriteBase / 
    
    RewriteRule ^cover/([0-9]*)(s|m)?\.jpg$ /cover.php?id=$1&size=$2 [L]
    RewriteRule ^dl/([^/]*)/([^/]*)$ /download.php?$1=$2 [L]
    RewriteRule ^track/([^/]*)\.mp3$ /song.php?id=$1 [L]
    RewriteRule ^my(/)([^/]*)$ /my.php?requested=$2 [L]
    RewriteRule ^album/(.*)-([0-9]{0,6})$ /album.php?id=$2 [L]
    RewriteRule ^a/([^/]*)$ /artist.php?name=$1 [L]
    RewriteRule ^a/([^/]*)/music$ /music.php?name=$1 [L]
    RewriteRule ^(artists|about|charts|contact|myprofile|editprofile|mymusic|uploadsongs|logout|genres|t)$ /$1.php [L]
    
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com(/)?.*$ [NC]
    RewriteRule .*\.(mp3)$ - [F,NC]
    
    # assume anything else is a username
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)$ /artist.php?name=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/music$ /music.php?name=$1 [L]
    
    ErrorDocument 404 /errors/404.php
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了