【问题标题】:How to pass variable with an apache RewriteRule?如何使用 apache RewriteRule 传递变量?
【发布时间】:2015-11-04 23:17:25
【问题描述】:

我正在尝试通过例如:

www.example.com/quote/20.html 

到:

www.example.com/quote.php?id=20

mod_rewite 开启且当前规则似乎没有通过变量:

Options +FollowSymLinks
Options -Indexes
# STRONG HTACCESS PROTECTION
<Files ~ "^.*\.([Hh][Tt][Aa])">
 order allow,deny
 deny from all
 satisfy all
</Files>


RewriteEngine on

RewriteRule quote/(.*).html quote.php?id=$1 

RewriteRule topic/(.*)/(.*).html topic.php?topic=$1&page=$2

【问题讨论】:

    标签: apache mod-rewrite url-rewriting friendly-url


    【解决方案1】:

    尝试以下方法:

    Options +FollowSymLinks -Indexes -MultiViews
    # STRONG HTACCESS PROTECTION
    <FilesMatch "\.(?i:htaccess)$">
        Order allow,deny
        Deny from all
        Satisfy all
    </FilesMatch>
    
    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} ^GET\ /quote\.php\?id=(\d+) [NC]
    RewriteRule ^quote\.php$ /quote/%1? [R=301,L,NC]
    
    RewriteRule ^quote/(\d+).html$ /quote.php?id=$1 [L]
    RewriteRule ^topic/([^/]+)/(.+).html$ /topic.php?topic=$1&page=$2 [L]
    

    【讨论】:

    • 当我将上半部分更改为“RewriteEngine On”时,我收到 500 内部错误。我改变了所有其余的但仍然没有进展..
    • ".htaccess: 预期为 但看到了 "
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-07
    相关资源
    最近更新 更多