简体   繁体   English

.htaccess-匹配子文件夹

[英].htaccess - match subfolder

this should be very easy, but still 这应该很容易,但是仍然

I need to have the following URL options: 我需要以下网址选项:

  1. domain.com domain.com
  2. domain.com/page/1234 domain.com/page/1234
  3. domain.com/someWords-MoreWords domain.com/someWords-MoreWords
  4. domain.com/buylink/1234 domain.com/buylink/1234

    • N1 and N2 needs to go to --> index.php N1和N2需要转到-> index.php
    • N3 --> second.php N3-> second.php
    • N4 --> third.php N4-> third.php

the following works for N1 and N2, but could not make N3 work. 以下内容适用于N1和N2,但无法使N3起作用。

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule page/([0-9]?[0-9]?[0-9]?[0-9]?) index.php?&page=$1

Give this a try (did not test it): 尝试一下(未测试):

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

RewriteRule ^page/([0-9]+)/?$ index.php?&page=$1 [L,S=2]
RewriteRule ^buylink/([0-9]+)/?$ third.php?&page=$1 [L]
RewriteRule ^([\w-]+)/?$ second.php?&page=$1 [L]

Update added flag S (thanks to @Prix): 更新添加的标志S (感谢@Prix):

The S flag will skip the conditions for the next 2 rules too S标志也将跳过接下来2条规则的条件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM