【发布时间】:2021-08-09 13:28:54
【问题描述】:
我有 3 个子目录,其中 index.php 文件具有相同的 url 参数:
example https://example.com/one/index.php?c=onestarhttps://example.com/two/index.php?c=onestarhttps://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
【问题讨论】:
-
@anubhava 你知道解决方案吗?
-
对不起,我不知道htaccess,我正在尝试一些重写规则代码
-
重写规则 ^index/([a-zA-Z]+)$ index.php?c=$1
-
您可以做的任何事情
-
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]] 选项 +MultiViews RewriteEngine On RewriteCond % {REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
标签: regex apache .htaccess mod-rewrite cpanel