【问题标题】:htaccess url RewriteRulehtaccess url 重写规则
【发布时间】:2010-01-11 12:36:40
【问题描述】:

这是我的网址

http://mydomain.com/Anonymous/47/comments.php

我的文件托管脚本包含大量重写,那么我怎样才能将这种特定类型的 url 重定向到 cmets.php 而不会与其他重写发生冲突。

我的 htaccess 文件

Options +FollowSymLinks

RewriteEngine on
##point to installation directory
##if it is the root dir,enter /
##else /otherdir
RewriteBase  /

RewriteCond %{QUERY_STRING} ^d=([a-zA-Z0-9]{8,12})$
RewriteRule ^$ download.php?id=%1&type=1 [L]

RewriteCond %{QUERY_STRING} ^d=([a-zA-Z0-9]{12})$
RewriteRule ^$ delete.php?id=%1 [L]

RewriteRule   ^file/([0-9]+)/(.*)$ download.php?id=$1&name=$2&type=2 [L]
RewriteRule   ^([a-z]{2})/file/([0-9]+)/(.*)$ download.php?setlang=$1&id=$2&name=$3&type=2 [L]
RewriteRule   ^myfolders/([0-9]+)-(.*)$ folders.php?fid=$1&name=$3&%{QUERY_STRING} [L]
RewriteRule   ^([a-z]{2})/myfolders/([0-9]+)-(.*)$ folders.php?setlang=$1&fid=$2&name=$3&%{QUERY_STRING} [L]

RewriteRule   ^topfiles/index([0-9]*)\.html$ top.php?s=$1&type=1 [L]
RewriteRule   ^([a-z]{2})/topfiles/index([0-9]*)\.html$ top.php?setlang=$1&s=$2&type=1 [L]

RewriteRule ^([a-z]{2})$ ?setlang=$1 [QSA,L]
RewriteRule ^([a-z]{2})/$ ?setlang=$1 [QSA,L]
RewriteRule ^([a-z]{2})/(.*)\.php$ $2.php?setlang=$1 [QSA,L]

RewriteRule ^content/([0-9a-zA-Z]+)\.html$ page_template.php?page=$1 [QSA,L]

<IfModule mod_security.c>
  # Turn off mod_security filtering.
  SecFilterEngine Off

  # The below probably isn't needed,
  # but better safe than sorry.
  SecFilterScanPOST Off
</IfModule>

<FilesMatch "\captcha.php$">
   Header set Cache-Control "max-age=1"
</FilesMatch>

【问题讨论】:

    标签: php apache mod-rewrite


    【解决方案1】:

    把它放在最后一个地方。要无论如何处理规则,请将其放在首位并添加[L] 标志。重写规则按照它们出现的顺序进行处理。请注意,如果您在 .htaccess 环境中执行此操作,则在没有实际目标的情况下成功重写后,重写规则将重新开始,因此您必须添加以下内容:

    RewriteRule ^comments\.php - [L]
    RewriteRule ^.*/[0-9]+/comments\.php comments.php [L,QSA]
    

    【讨论】:

      【解决方案2】:

      试试这个规则:

      RewriteRule ^Anonymous/[0-9]+/comments\.php$ comments.php [L]
      

      【讨论】:

        猜你喜欢
        • 2011-12-06
        • 2016-11-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-02
        相关资源
        最近更新 更多