将网站从 .html 转换为 .php
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8084727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Converting site from .html to .php
提问by Lars
my site has now become sufficiently large for me to think it's necessary to convert the pages to php pages to help me update it in the future. The problem is: my site has a number of links to it on various websites across the web. Eg these links point to www.example.com/page1.html but the page is now going to be renamed www.example.com/page1.php
我的网站现在已经变得足够大,我认为有必要将页面转换为 php 页面以帮助我将来更新它。问题是:我的网站在网络上的各种网站上有许多指向它的链接。例如,这些链接指向 www.example.com/page1.html 但该页面现在将重命名为 www.example.com/page1.php
How would people get around this problem? Simply redirect the html page to the php page? Are there any alternatives? Does this have any implications for SEO?
人们将如何解决这个问题?只需将 html 页面重定向到 php 页面?有没有其他选择?这对 SEO 有什么影响吗?
Thanks
谢谢
回答by Aerik
回答by Marc B
The least intrusive method is to simply have your webserver treat .html files as PHP files. That way your links can stay intact, and progressively replacing static .html pages with actual php-enabled pages can be done in an essentially transparent method to users.
干扰最少的方法是简单地让您的网络服务器将 .html 文件视为 PHP 文件。这样您的链接就可以保持完整,并且可以通过对用户基本上透明的方法逐步用实际启用 php 的页面替换静态 .html 页面。
Remember, there is no such thing as a "PHP script". There are only files that contain <?php ... ?>
code blocks, which will get interpreted/executed when the containing file is passed through PHP.
请记住,没有“PHP 脚本”这样的东西。只有包含<?php ... ?>
代码块的文件,当包含文件通过 PHP 时将被解释/执行。
Unless some of your html pages contain SAMPLES of php code that could be misinterpreted as actual code, then there shouldn't be any issues with making run through PHP.
除非您的某些 html 页面包含可能被误解为实际代码的 php 代码示例,否则通过 PHP 运行应该没有任何问题。
As a minor side benefit, it wouldn't be immediately obvious that your site is running on PHP, as all the urls would say ".html". But then, that's security by obscurity and shouldn't be counted on to be anything in the way of real security.
作为一个次要的好处,您的网站在 PHP 上运行不会立即明显,因为所有的 url 都会说“.html”。但是,这是默默无闻的安全性,不应指望成为真正安全性的任何东西。
回答by HappyDeveloper
You can do a 301 redirect (this works fine for SEO), or just rewrite the URLs so page1.html points to page1.php internally.
你可以做一个 301 重定向(这对 SEO 很有效),或者只是重写 URL,这样 page1.html 在内部指向 page1.php。
Both solutions can be done with the .htaccessfile (assuming you are using apache as your webserver)
两种解决方案都可以使用.htaccess文件完成(假设您使用 apache 作为您的网络服务器)
回答by Xleedos
Maybe consider using a tool such as Dreamweaver to manage your website. That way you can easily rename pages and update the links with a few clicks.
也许可以考虑使用 Dreamweaver 等工具来管理您的网站。这样,您只需点击几下即可轻松重命名页面并更新链接。
:)
:)
回答by Thejeswar Reddy
As answered by Marc B,
正如马克 B 的回答,
there is no such thing as a "PHP script". There are only files that contain code blocks, which will get interpreted/executed when the containing file is passed through PHP.
没有“PHP 脚本”这样的东西。只有包含代码块的文件,当包含文件通过 PHP 时将被解释/执行。
i would say that it's true and if you want to absolutely turn your html files into php files simply put <?php
before your <DOCTYPE html!>
line and then ?>
after your </html>
line save it and rename it as example.phpif it is example.html
我会说这是真的,如果你想绝对地将你的 html 文件变成 php 文件,只需将它放在<?php
你的<DOCTYPE html!>
行之前,然后?>
在你的</html>
行之后保存并重命名为example.php如果它是example.html
if you are windows8 or higher user then click on 'View' in file explorer and then check 'File name Extension'. Now you'll be able to see the extension example.html and many other files extensions like .jpg, .mp3 e.t.c...., This helps you to easily rename exactly like example.php but not example.php.html as .html will not be visible if you are not checked File name Extension.
如果您是 windows8 或更高版本的用户,请单击文件资源管理器中的“查看”,然后选中“文件扩展名”。现在您将能够看到扩展名 example.html 和许多其他文件扩展名,如 .jpg、.mp3 等...,这有助于您轻松地将 example.php 重命名为 .html,但不能将 example.php.html 重命名为 .html如果未选中文件名扩展名,则将不可见。
回答by Vamsi Krishna B
I would suggest that you use CodeIgniter(kickass php framework).
我建议您使用CodeIgniter(kickass php 框架)。
You can maintain the existing site structure also, by making use of CodeIgniter's URL suffix
option .
您还可以通过使用 CodeIgniter 的URL suffix
选项来维护现有的站点结构。