【问题标题】:mod rewrite .htaccess expressionengine remove index.php and a specific subdirectorymod rewrite .htaccess 表达式引擎删除 index.php 和特定的子目录
【发布时间】:2012-05-24 17:31:14
【问题描述】:

不想问这个问题,但我已经把头撞在桌子上一段时间了,似乎无法理解。我正在使用 ExpressionEngine,并且正在使用 mod_rewrite 从我的所有 URL 中删除 index.php。这很好用。此外,我希望将 myurl.com/adwords/(anything) 中的任何内容重写为 myurl.com/(anything)。我的正则表达式和 htaccess Skillz 很弱。这是我在 .htaccess 中的内容:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^/adwords/(.*)$
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

所以我想我说的是任何以 /adwords/(something) 结尾的内容,捕获该内容,然后通过 $1 将其附加到 index.php 的末尾。我猜这很简单。谢谢!

【问题讨论】:

    标签: .htaccess mod-rewrite expressionengine


    【解决方案1】:

    您正在寻找的规则可能很简单

    RewriteRule ^adwords/(.*)$ index.php/$1 [L]
    

    不需要重写条件,但我想知道...你真的想将http://myurl.com/adwords/foo 重写为http://myurl.com/index.php/foo,而不是http://myurl.com/index.php?a=foo 吗?

    如果您还想将 http://myurl.com/baa/adwords/foo 之类的内容重写为 http://myurl.com/baa/index.php/foo,则必须省略 ^:

    RewriteRule adwords/(.*)$ index.php/$1 [L]
    

    顺便说一句,你可以在这里测试你的大部分重写规则:http://htaccess.madewithlove.be/

    【讨论】:

    • 哇,那个网站太棒了。解决了我的问题。非常感谢!
    猜你喜欢
    • 2014-02-21
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    • 2012-05-02
    相关资源
    最近更新 更多