简体   繁体   English

.htaccess重写和重定向

[英].htaccess rewriting and redirection

I am working on a site on a new shared server, so the domain name is not active. 我正在新共享服务器上的站点上工作,因此域名无效。 I am using a temporary url, something like http://100.75.100.120/~mywebsite 我使用的是临时网址,例如http://100.75.100.120/~mywebsite

I am changing a lot of .html files into .php and am also hiding the file suffix in the links to the pages. 我正在将许多.html文件更改为.php,并且还将文件后缀隐藏在页面的链接中。 So I need help with some rewrite/redirect rules. 因此,我需要一些重写/重定向规则的帮助。

Can someone help me with the rules so that when someone looks for the old .html file, they are shown the .php file. 有人可以帮我制定规则,以便当有人寻找旧的.html文件时,他们会看到.php文件。 And when they look for the file without a suffix they are shown the .php file without revealing the suffix? 当他们查找不带后缀的文件时,会显示.php文件而不显示后缀吗?

I have tried lots of different things, but really don't know what I am doing. 我尝试了很多不同的方法,但实际上不知道我在做什么。 Doing it in this temp url environment makes it more difficult. 在此临时url环境中执行此操作会更加困难。 At the moment I am writing a rule for each page eg 目前,我正在为每个页面编写规则,例如

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^index.html http://100.75.100.120/~mywebsite
RewriteRule ^other/$ http://100.75.100.120/~mywebsite/other.php [R=301,L]
# ... and many more

I am sure there would be a much better way. 我相信会有更好的方法。 Many thanks. 非常感谢。

Another problem I have come across is there are directories with the same names as some of the php files. 我遇到的另一个问题是目录与某些php文件具有相同的名称。

You can redirect each request with 您可以使用重定向每个请求

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://100.75.100.120/~mywebsite/$1 [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM