Regex 如何为多个子目录制定htaccess重写规则

Regex 如何为多个子目录制定htaccess重写规则,regex,apache,.htaccess,mod-rewrite,cpanel,Regex,Apache,.htaccess,Mod Rewrite,Cpanel,我有3个子目录,其中的index.php文件具有相同的url参数: 示例https://example.com/one/index.php?c=onestar https://example.com/two/index.php?c=onestar https://example.com/three/index.php?c=onestar 我使用下面的代码从URL中删除.php RewriteEngine On options +MultiViews RewriteEngine On Rew

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

  • 示例https://example.com/one/index.php?c=onestar
  • https://example.com/two/index.php?c=onestar
  • https://example.com/three/index.php?c=onestar
我使用下面的代码从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:

选项-多视图
重新启动发动机
#http=>https
重写cond%{HTTPS}!在…上
重写规则^https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301,NE]
#/one/index/onestar=>/one/index.php?c=onestar
重写规则^([\w-]+)/index/([\w-]+)/?$$1/index.php?c=$2[L,NC,QSA]
#hide.php
重写cond%{REQUEST_FILENAME}-D
RewriteCond%{REQUEST_FILENAME}.php-f
重写规则^(+?)/?$$1.php[L]

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

选项-多视图
重新启动发动机
#http=>https
重写cond%{HTTPS}!在…上
重写规则^https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301,NE]
#/one/index/onestar=>/one/index.php?c=onestar
重写规则^([\w-]+)/index/([\w-]+)/?$$1/index.php?c=$2[L,NC,QSA]
#hide.php
重写cond%{REQUEST_FILENAME}-D
RewriteCond%{REQUEST_FILENAME}.php-f
重写规则^(+?)/?$$1.php[L]

@anubhava你知道这个解决方案吗?对不起,我不知道htaccess,我正在尝试一些重写规则codeRewriteRule^index/([a-zA-Z]+)$index.php?c=$1你能做的任何事情都可以帮助RewriteEngine在RewriteCond%{HTTPS}关闭RewriteRule^(.*)$HTTPS://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]]选项+重写条件%{REQUEST_FILENAME}上的多视图重写引擎-d RewriteCond%{REQUEST\u FILENAME}.php-f RewriteRule.*\。php${REQUEST_FILENAME}.php[QSA,L]@anubhava你知道这个解决方案吗?对不起,我不知道htaccess,我正在尝试一些重写规则codeRewriteRule^index/([a-zA-Z]+)$index.php?c=$1你可以做的任何事情来帮助重写引擎重写第二次%{HTTPS}关闭重写规则^(.*)$HTTPS://%{HTTP_HOST}%{REQUEST_URI L,R=301]]选项+重写条件%{REQUEST_FILENAME}上的多视图重写引擎-d RewriteCond%{REQUEST\u FILENAME}.php-f RewriteRule.*\。php$%{REQUEST_FILENAME}.php[QSA,L]感谢它的工作。但是如果我把它变成动态的,而不是使用(一|二|三),对吗?我使用(.*)是的,我可以变成动态的,规则可以进一步更新。谢谢它的工作。但是如果我把它变成动态的而不是使用(一|二|三),我会使用(.*)是的,我可以变成动态的,规则会进一步更新。