【问题标题】:how to sepratly on admin folder in htaccess如何单独在 htaccess 中的管理文件夹上
【发布时间】:2015-02-08 16:02:03
【问题描述】:

朋友们,我是 php 开发者,我在示例中自定义了 url

发件人:http://example.net/page.php?post_id=contact/

收件人:http://example.net/contact/

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / 
#RewriteBase use only home/phtml/www/ this kind of path
RewriteRule ^([a-zA-Z-/]+)$ page.php?post_id=$1 [QSA]
RewriteRule ^([a-zA-Z-/]+)/$ page.php?post_id=$1 [QSA]
</IfModule>

它在上面的 htaccess 代码上工作正常,但它有一些问题。什么是用于控制面板目的的“admin”文件夹。其中如何正确重定向到http://example.net/admin/ htaccess 中的任何选项?

我的错误是:http://example.net/page.php?post_id=admin/

如何解决?

【问题讨论】:

    标签: regex apache .htaccess url-rewriting friendly-url


    【解决方案1】:

    您可以跳过重写规则中的所有目录。使用:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase / 
    
    # If the request is not for a valid directory
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-zA-Z/-]+)/?$ page.php?post_id=$1 [L,QSA]
    
    </IfModule>
    
    • 您还应该在字符类中的第一个或最后一个位置保留未转义的连字符。
    • 我使用可选的尾随斜杠将您的 2 条规则合并为一条。

    【讨论】:

    • 我需要多个 url 自定义示例 RewriteRule ^([a-zA-Z/-]+)/?$ admin/index.php?post_id=$1 [L,QSA]
    • 对不起,多个 url 自定义示例 RewriteRule 是什么意思
    • 如果我需要另一个 php 文件自定义示例:RewriteRule ^([a-zA-Z/-]+)/?$ category.php?post_id=$1 [L,QSA]
    • 这行不通,因为它与第一条规则的模式相同。你可以有不同的路径,比如RewriteRule ^cat/([a-zA-Z/-]+)/?$ category.php?post_id=$1 [L,QSA]
    • 这在我们的 htaccess 中不起作用^cat/([a-zA-Z/-]+)/?$ category.php?post_id=$1 [L,QSA]
    猜你喜欢
    • 2014-07-12
    • 2010-12-15
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    • 2021-10-28
    • 2011-06-04
    相关资源
    最近更新 更多