【问题标题】:Using wildcard on other page addresses than the static ones在静态页面地址以外的其他页面地址上使用通配符
【发布时间】:2013-02-15 18:32:28
【问题描述】:

我想使用通配符,以便允许任何页面地址。但我想使用一些静态页面地址,如用户登录、注册等。我目前正在使用这种方法,但正如我所料,它会尝试在每个页面地址上找到page.php

# KONTO
RewriteRule ^skapa-ett-konto$    account-create.php [L]
RewriteRule ^logga-ut$    account-logout.php [L]


# KONTO: Sidor som behöver laddas in genom jQuery/AJAX
RewriteRule ^slutfor-registreringen$    configurations/javascripts/ajax-form/account-create.php [L]
RewriteRule ^logga-in$    configurations/javascripts/ajax-form/account-login.php [L]



# --------------------------------------- #



# PROFIL
RewriteRule ^anvandare/([a-z0-9]+)$    profile.php?u=$1 [L]



# --------------------------------------- #



# ENSKILDA FILER
RewriteRule ^(.*)$    page.php?p=$1 [L]

我怎样才能让RewriteRule 使用通配符到其他页面地址而不是静态地址?

提前致谢。

【问题讨论】:

    标签: .htaccess mod-rewrite wildcard


    【解决方案1】:

    如果我理解正确,您想从最后一条规则中排除一些现有页面,例如 loginregistration。排除它们的方法是这样的:

    # ENSKILDA FILER
    # Add other pages to exclude here
    RewriteCond %{REQUEST_URI}  !(page\.php|login|registration)  [NC]
    RewriteRule ^(.*)$    page.php?p=$1 [L]
    

    【讨论】:

      【解决方案2】:

      如果所有其他地址都不是文件,您可以在 page.php 规则前面加上

      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule .* page.php?p=$0 [L]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-10-08
        • 1970-01-01
        • 2011-01-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多