【问题标题】:How to redirect .php to .html using .htaccess [duplicate]如何使用 .htaccess 将 .php 重定向到 .html [重复]
【发布时间】:2018-01-12 06:34:55
【问题描述】:

我在测试服务器上上传了我的代码,链接如下

http://dynamicwebsite.co.in/kk/ksmotors/tafe/aboutus.html

现在我想当有人点击下面的 URL 然后用户重定向到上面的 URL

http://dynamicwebsite.co.in/kk/ksmotors/tafe/index.php?page=aboutus.php

我使用了以下 .htaccess 代码,但它不起作用

RewriteEngine On

#RewriteRule ^index.php?page=(.*).php/?$ $1/$2.html$3 [R=301,L]
#RedirectMatch 301 /form/5/.* www.example.com/form/12/name.html

RedirectMatch 301 /index.php?page=aboutus.php http://dynamicwebsite.co.in/kk/ksmotors/tafe/aboutus.html

#Disable php and html files in storage folders
RedirectMatch 403 (admin\/accessory\/images|admin\/careers\/images|admin\/categories\/images|admin\/css|admin\/images|admin\/jqgrid|admin\/models\/images|admin\/submodels\/images|css|images|js|php-captcha|resume|spec_doc).+\.(php|php3?|phtml|html)$

#Disable Directory Listing
Options -Indexes

你能解释一下出了什么问题吗? 请帮忙。 谢谢

【问题讨论】:

标签: php html .htaccess url redirect


【解决方案1】:

在 .htaccess 文件中添加以下代码

RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]

重写网址

此示例将一个 URL 重写为另一个 URL。这会将 example.com/1.html 重写为 example.com/abc.php?id=1

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9]+).html /abc.php?id=$1 [QSA,L]

参考link

【讨论】:

【解决方案2】:

如果你想从 php 重定向到 html,你可以在你的 .htaccsess 文件中添加它。在代码中添加您的页面名称

RewriteEngine on 
RewriteBase / RewriteCond %{THE_REQUEST} \ /(.+)\.php 
RewriteRule ^ /%1.html [L,R=301] 
RewriteRule ^pagename\.html$ pagename.php [T=application/x-httpd-php,L] 
RewriteEngine on 
rewritecond %{http_host} ^xyz.org [nc] 
rewriterule ^(.*)$ http://xyz./$1 [r=301,nc] 
RewriteRule ^index\.html$ / [NC,R,L] 
ErrorDocument 404 /404.html

【讨论】:

    猜你喜欢
    • 2014-05-30
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    • 2015-10-22
    相关资源
    最近更新 更多