.htaccess 如何从重写规则中删除文件扩展名

qyuhtwio  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(140)

我有一些麻烦与国防部重写规则,并希望有人能够帮助...
我有一些类似example.com/o/overview/?did=10的url,我已经添加了一个重写规则到我的htaccess,将url重写为example.com/o/overview/10.php,但是我不希望.php出现在结尾,这就是我遇到麻烦的地方。
我已经尝试添加另一个重写规则,删除文件扩展名(.php或.html),但似乎不工作。任何帮助或指导将不胜感激。下面是htaccess:

# Remove file extensions from url
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteRule ^o/overview/([^/]*)\.php$ /o/overview/?did=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.+?)/?$ /$1.html [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
wfauudbj

wfauudbj1#

使用显示示例,请尝试以下.htaccess规则文件

请确保:

  • 将.htaccess规则文件与o文件夹放在沿着(不是放在里面,而是放在旁边)。
  • 将您的.php或.html文件放在/o/overview文件夹中。
  • 请确保在测试URL之前清除浏览器缓存。
RewriteEngine ON
Options +FollowSymLinks -MultiViews
RewriteBase /o/overview/

##Rules for, From url example.com/o/overview/79 to https://example.com/o/overview/index.php?did=79
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(o/overview)/([^/]*)/?$ $1/index.php?did=$2 [QSA,L]

##Rules for url example.com/o/overview/?did=10 to example.com/o/overview/10.php
RewriteCond %{THE_REQUEST} \s/(o/review)/?\?did=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(o/overview)/([^/]*)/?$ $1/$2.php [QSA,NC,L]

RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(o/overview)/([^/]*)/?$ $1/$2.html [QSA,NC,L]

相关问题