htaccess 重定向到子文件夹和文件

htaccess redirect to subfolder and file

我认为有很多 htaccess 重定向示例,但我找不到与我相似的案例。

我的根目录有很多子文件夹

/suppliers
 |- /suppliers/abc
 |- /suppliers/xyz

/merchants
 |- /merchants/abc
 |- /merchants/xzy

等等

我想在输入时重定向它们

/m/yyy -> /merchants/yyy/index.php
/m/yyy/abc -> /m/merchants/yyy/abc.php
/m/yyy/abc/ -> /m/merchants/yyy/abc/index.php

谁能告诉我该怎么做?

您可以在站点根目录 .htaccess 中使用这些规则:

RewriteEngine On

# /m/yyy rule
RewriteRule ^m/([\w-]+)/?$ merchants//index.php [L,NC]

# /m/yyy/abc rule
RewriteRule ^m/([\w-]+)/([\w-]+)$ merchants//.php [L,NC]

# /m/yyy/abc/ rule
RewriteRule ^m/([\w-]+)/([\w-]+)/$ merchants///index.php [L,NC]