重命名 URL 中的文件.php 文件

问题描述

我有一个名为 DROP INDEX IF EXISTS user_skills ; CREATE INDEX user_skills ON user_table USING gist (array_to_string(user_skills,' ') gist_trgm_ops) ; -- gin_trgm_ops and gist_trgm_ops indexes are compliant with the LIKE operator and the regular expressions 的文件,并希望通过 .htaccess 生成 url filename-step1.php

我当前的 domain.com/filename/step1 文件如下所示:

.htaccess

目前,这适用于从 url 中删除 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] 标记。只需要修复目录。

解决方法

您可以添加一个 RewriteRule 以重定向到 $1/$2.php

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)/(.*)$ /$1-$2.php [NC,L]
</IfModule>

因此,filename/step1 将触发 filename-step1.php 文件。

,

我在这里提供了 2 个解决方案,请一次仅在您的 .htaccess 文件中尝试一个。使用您显示的示例,您能否尝试遵循通用规则。

RewriteEngine ON
RewriteCond %{HTTP_HOST} domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/(.*)/?$ $1-$2.php [NC,L]


或者,如果您正在寻找特定的网址 filename/step1,请尝试关注。

RewriteEngine ON
RewriteCond %{HTTP_HOST} domain\.com [NC]
RewriteRule ^(filename)/(step1)/?$ $1-$2.php [NC,L]

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...