如何为多个子目录创建 htaccess 重写规则

how to make htaccess rewrite rule for multiple sub directories

我有 3 个子目录,其中 index.php 个文件具有相同的 url 参数:

我正在使用以下代码从 URL

中删除 .php
RewriteEngine On

options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

如何使其对 SEO 友好 https://example.com/one/index/onestar。还有如何让它动态地在将来添加多个目录,比如 https://example.com/four/index/onestar

您可以在站点根目录 .htaccess 中使用此代码:

Options -MultiViews
RewriteEngine On

# http => https
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

# /one/index/onestar => /one/index.php?c=onestar
RewriteRule ^([\w-]+)/index/([\w-]+)/?$ /index.php?c= [L,NC,QSA]

# hide .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ .php [L]