gpt4 book ai didi

apache - 如何使用 .htaccess 规则将 .php 重写为 .html?

转载 作者:行者123 更新时间:2023-12-05 03:46:14 25 4
gpt4 key购买 nike

我尝试过,但失败了。原始网址

https://www.sitename.com/user/login/index.php
https://www.sitename.com/user/dashboard/index.php

浏览器应该显示的URL

https://www.sitename.com/user/login.html
https://www.sitename.com/user/dashboard.html

这个我试过了,没用

RewriteEngine on  
RewriteBase /

RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php http://%{HTTP_HOST}/user/$1.html [R=301,L]

RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html http://%{HTTP_HOST}/user/$1.php [L]

最佳答案

能否请您尝试以下。使用您显示的示例编写和测试。请确保在测试您的 URL 之前清除浏览器缓存。

RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/([^/]*)/([^.]*)\.html/?$ [NC]
RewriteRule ^(.*)$ %1/%2/index.php [L]

关于apache - 如何使用 .htaccess 规则将 .php 重写为 .html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65389336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com