为什么如果我把一个" - "破折号在我的htaccess的规则不起作用? [英] Why if I put a "-" dash in a rule in my htaccess doesn't work?

查看:238
本文介绍了为什么如果我把一个" - "破折号在我的htaccess的规则不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的规则,其中的我们的家店面重定向到一个不同的地方比其他普通页面的规则:

I have the following rules, the one "our-stores" redirects to a different place than the other "PLAIN PAGES" rules:


    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RedirectMatch 302 /construction.html http://www.{website}.com/construction-services
    RedirectMatch 302 /construction/endless-pools.html http://www.{website}.com/construction-services/endless-pools

    # PRODUCT AND SERVICES
    RewriteCond %{REQUEST_URI} !\.html$
    RewriteRule ^(.*)/(.*)$ /rewrite.php?sub=$1&second=$2 [NC]

    # PLAIN PAGES
    #RewriteRule ^/$ /index.php [L,NC]
    RewriteRule ^signup-free$ /signup-free.php [L,NC]
    RewriteRule ^about$ /content.php?page=1 [L,NC]
    RewriteRule ^links$ /content.php?page=2 [L,NC]
    RewriteRule ^portfolio$ /portfolio.php [L,NC]
    RewriteRule ^our-stores$ /our-stores.php [L,NC]
    RewriteRule ^contact$ /contact.php [L,NC]
    RewriteRule ^products-list$ /lists.php?action=products [L,NC]
    RewriteRule ^services-list$ /lists.php?action=services [L,NC]

当我键入 /我们​​家店面的Apache重定向到:<?code> /我们​​-店/分=我们家店面和放大器;第二=

When I type /our-stores apache redirects to: /our-stores/?sub=our-stores&second=

我不明白这一点,因为剩下的(注册,无约,链接,组合...等)工作正常。

I don't get it because the rest (signup-free, about, links, portfolio... and so on) are working fine.

任何人可以帮助我解决这个吗?

Can anybody help me with this one?

感谢你。

推荐答案

通用的规则已被移到了底部,而 REQUEST_FILENAME 条件时,静态重定向之下。此外,我添加了一个 / <?/ code>在每个特定的重定向匹配可选尾随斜线。最后,一​​般的规则是提高不使用。* ,而是匹配所有到第一个 / 的一个贪心不足的方式。然后使用 + / ,以确保至少有一个字符为present。 URL以一个斜线因此不匹配。如果你有一些仿制药没有第二= ,变回。*

The generic rule has been moved to the bottom, and the REQUEST_FILENAME conditions moved beneath the static redirects. Further, I have added a /? to match an optional trailing slash on each of the specific redirects. Finally, the generic rule is improved not to use .*, but rather to match everything up to the first / in a less greedy way. Then it uses .+ after the / to make sure at least one character is present. Urls with a trailing slash would therefore not match it. If you have some generics without a second=, change back to .*.

在htaccess的测试,所有这些都能正常工作。

All of these work correctly in the htaccess tester.

RedirectMatch 302 /construction.html http://www.{website}.com/construction-services
RedirectMatch 302 /construction/endless-pools.html http://www.{website}.com/construction-services/endless-pools

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^signup-free/?$ /signup-free.php [L,NC]
RewriteRule ^about/?$ /content.php?page=1 [L,NC]
RewriteRule ^links/?$ /content.php?page=2 [L,NC]
RewriteRule ^portfolio/?$ /portfolio.php [L,NC]
RewriteRule ^our-stores/?$ /our-stores.php [L,NC]
RewriteRule ^contact/?$ /contact.php [L,NC]
RewriteRule ^products-list/?$ /lists.php?action=products [L,NC]
RewriteRule ^services-list/?$ /lists.php?action=services [L,NC]

# PRODUCT AND SERVICES
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule ^([^/]+)/(.+)$ /rewrite.php?sub=$1&second=$2 [NC]

这篇关于为什么如果我把一个&QUOT; - &QUOT;破折号在我的htaccess的规则不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆