【问题标题】:Cannot remove extension from urls无法从网址中删除扩展名
【发布时间】:2022-01-12 15:39:14
【问题描述】:

我正在尝试从 url 中删除 .php 扩展名,但我不走运尝试在堆栈上提供给我的已知解决方案,但我需要帮助。 (Guide i followed) 我已将所需的 RewriteConditions 和规则添加到 .htaccess 文件中,并将我的 href 更新为以下内容,但它仍然无法正常工作。当我使用以下值保存 .htaccess 文件时,当我尝试访问它时出现“页面不存在”的错误。

.htaccess

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

RewriteCond %{REQUEST_URI} !^(.+)\.html$
RewriteCond %{REQUEST_URI} !^(.+)\.htm$
RewriteCond %{REQUEST_URI} !^(.+)\.php$
RewriteCond %{REQUEST_URI} !^(.+)\.js$
RewriteCond %{REQUEST_URI} !^(.+)\.css$
RewriteCond %{REQUEST_URI} !^(.+)\.jpg$
RewriteCond %{REQUEST_URI} !^(.+)\.png$
RewriteCond %{REQUEST_URI} !^(.+)\.gif$
RewriteCond %{REQUEST_URI} !^(.+)\.swf$
RewriteCond %{REQUEST_URI} !^(.+)\.xml$
RewriteCond %{REQUEST_URI} !^(.+)\.ico$
RewriteCond %{REQUEST_URI} !^(.+)\.txt$
RewriteCond %{REQUEST_URI} !^index\.html$
RewriteCond %{REQUEST_URI} !^index\.php$
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^(.+)/$

将 href 从 register.php 更改为 register 像这样

<a href="register"><?php echo strtoupper(t('register', 'register')); ?></a>

我在尝试访问它时遇到的错误是该页面不存在。

【问题讨论】:

  • 我们应该怎么知道?你的实际问题是什么?我们不知道您的设置,您知道,但您没有告诉我们。那么我们应该怎么知道呢? echo strtoupper(t('register', 'register')); 是什么?我们不知道那条线是做什么的。你在哪里编写了这两个重写指令?你http服务器的日志文件说什么?你的浏览器说什么?您收到的请求返回的结果是什么?

标签: php html apache .htaccess mod-rewrite


【解决方案1】:

试试这个:

RewriteRule ^(.*)$ $1.php

不要将任何 .php 添加到您的 href 属性中。

【讨论】:

  • 如果 OP 发布的RewriteRule 显然没有实现重写传入的请求,为什么你认为这个RewriteRule 会?
  • 嗨。我已经更新了我的帖子和 .htaccess 内容,因为我错过了可能导致问题的大部分内容。
猜你喜欢
  • 1970-01-01
  • 2017-05-08
  • 2011-09-25
  • 1970-01-01
  • 1970-01-01
  • 2013-01-09
  • 1970-01-01
  • 1970-01-01
  • 2017-02-24
相关资源
最近更新 更多