.htaccess redirect .html to non .html not working

人盡茶涼 提交于 2020-01-06 18:40:24

问题


using this in my .htaccess:

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

But the site is displaying a 404 Not Found, even though I have the file.

The file is ishared.html. The redirect works, but it takes to a not found, if you go to http://headupshouldersback.com/ishared.html

Any tips? Thanks!

EDIT: The following gave me 500 server error on my site:

RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
RewriteRule ^(.*) /$1.html [QSA,L]

回答1:


After your redirection:

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

Add to the next line:

RewriteRule ^(.*) /index.php?page=$1.html [QSA,L]

It is going to work. This will show the contents of ishared.html if you do the request for ishared.

EDIT:

It got into a loop, sorry, you need to use some php code.

index.php:

<?php file_get_contents( (isset($_GET['page'])) ? $_GET['page'] : "error.html"); ?>


来源:https://stackoverflow.com/questions/24294308/htaccess-redirect-html-to-non-html-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!