首页 > 解决方案 > htaccess如何删除url中的php和html

问题描述

我的网站有问题。我无法通过 url 重写来隐藏 .html 和 .php 。我可以用我的 .htaccess 文件隐藏其中一个,但不能同时隐藏两者。我试图将 .php 转换为 .html 但它不起作用。我已经看到该主题的 stackoverflow 中有很多主题。我尝试了他们所说的一切,并多次破坏了我的网站 XD 没有任何效果。我也尝试过其他网站的解决方案,但也没有任何效果。

也许我错过了一些东西。也许我做错了什么我不知道。也许我的网站是特定的。这是我的网站:elisabethluquetportfolio.com

你能帮我解决这个问题吗?我迷路了。

谢谢 :)

编辑:这是我的实际 htaccess :

#reecriture des liens pour éviter de laisser apparaître .html dans l'url
RewriteEngine On
#Remove .html suffix
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html  [L]

# 301 permanent redirect all .html to non .html pour rediriger les liens 
dont on a enlevé le html
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

如果我为 .php 执行相同的代码,通过将 .html 替换为 .php 将不起作用。它不起作用,因为我不能两次拥有这段代码,用于 html 和 php。

我也尝试过:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

它不起作用。

我也尝试在 html 中重命名 php,但它不起作用。当它不起作用时,我的浏览器告诉我它找不到该页面。

我没有尝试过的所有代码,因为我尝试了很多但没有记录。我应该这样做,尤其是为了不多次尝试相同的事情并向您展示我所做的事情。

标签: phphtml.htaccess

解决方案


推荐阅读