【问题标题】:How to convert individual .php page to .html extension using URL rewriting如何使用 URL 重写将单个 .php 页面转换为 .html 扩展名
【发布时间】:2017-07-06 23:01:38
【问题描述】:

我的 .htaccess 文件代码看起来像

# -FrontPage-

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>

ErrorDocument 404 /404.html

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+).html$ car.php?urlname=$1


RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+).html$ america-tour-packages.php?urlname=$1


RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

这是我在 .php 中创建的单个页面,并想使用重写 RULE 将其扩展名转换为 .html 但正常规则不起作用,请建议

>RewriteEngine on
>RewriteRule ^([a-zA-Z0-9_-]+).html$ america-tour-packages.php?urlname=$1

【问题讨论】:

  • 我不知道,但我在 One.com 有一个服务器,你可以选择 .html 或 .php,两者都适用于同一个 .php 文件

标签: php html apache .htaccess mod-rewrite


【解决方案1】:

试试这个:

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php

当您访问 test.html 时,系统会查找:test.php

【讨论】:

  • 这个不行,它还在打开.php页面
  • 从你的 .htaccess 中删除所有代码并只写这两行确保你的 mod rewrite 已启用并点击像“domainname/test.html”这样的 url,它将在内部重定向到“domainname/test.php” ”。试试这个让我知道如果你发现任何问题,因为我这边它正在工作。
  • 嗨,是的,它可以工作,但只有当我们单独放置它时,正如您在代码 car.php 中看到的那样,如果我们删除那辆车,所有代码都被写入其中以动态生成页面。 php 代码从那里停止打开和生成内部页面。如果我们将两者放在一起,那么 RewriteRule 上的 RewriteEngine ^(.*)\.html$ $1.php 一个不起作用
  • 我认为你不需要指定页面名称只有两行就足够了我已经测试了localhost/angular/test.html?id=123 并且在 test.php 我得到了 $_GET['id'];和 test2.html 也一样。两者都工作正常
  • 您好,亲爱的,car.php 不仅仅是一个单独的页面,这是创建多个详细列表页面的页面,通过里面编写的代码,所以它动态调用将它的 URL 转换为 .html,
猜你喜欢
  • 2015-05-18
  • 2021-05-14
  • 1970-01-01
  • 2011-02-15
  • 1970-01-01
  • 2012-02-06
  • 1970-01-01
  • 1970-01-01
  • 2022-03-04
相关资源
最近更新 更多