简体   繁体   English

半直接文件访问与index.php控制器

[英]Semi-direct file access vs index.php controller

Quick question I've had here which is a bit of a dilemma. 我在这里有一个简短的问题,这有点两难。 I have searched already but cant find a concise answer. 我已经搜索过,但找不到简明的答案。

I currently have on my website which is php based, a global index.php file which serves all requests so there's included in that file, a header, center part, a footer. 目前,我的网站上有一个基于php的全局index.php文件,该文件可以处理所有请求,因此该文件中包括页眉,中间部分和页脚。 This is globally setup for every page so that all that changes is the site center - see code below: 这是每个页面的全局设置,因此所有更改都是站点中心-请参见下面的代码:

require_once("assets/template/$theme_name/header.php"); //Global Header
require_once('process.php'); //Site Center
require_once('assets/template/default/footer.php'); //Global Foote

This has worked fine so far, and I'm currently using a query string to do the rest (nginx converting website.com/index.php?pg=pagename to website.com/pagename 到目前为止,此方法运行良好,目前我正在使用查询字符串来完成其余操作(nginx将website.com/index.php?pg=pagename转换为website.com/pagename

What I'm wondering is whether it would be safe and beneficial to just include the header and footer on each page, and have every user access the page via the actual page file which is located in a pages folder. 我想知道的是,仅在每个页面上包含页眉和页脚,并让每个用户通过位于页面文件夹中的实际页面文件访问页面是否安全和有益。 Or is my current method good? 还是我目前的方法好? Any effect on SEO? 对SEO有影响吗? I already have nginx rewrite code put together (just not implemented) so that website.com/pagename will be accessing website.com/pages/pagename.php 我已经将nginx重写代码放在一起(只是未实现),以便website.com/pagename将访问website.com/pages/pagename.php

Please let me know your opinion! 请让我知道您的意见!

Thanks so much! 非常感谢!

What you're talking about doing is called refactoring. 您正在谈论的事情叫做重构。 You're changing the implementation without having any noticeable effect on your users. 您正在更改实现,而对用户没有任何明显影响。 The refactoring, in and of itself, won't affect SEO. 重构本身不会影响SEO。

Now to what, in my opinion, is the more interesting question: why are you considering doing this change? 我认为现在有一个更有趣的问题:您为什么考虑进行此更改? From my vantage point, making this change will increase the amout of duplicated code (aka reduce the amount of code re-use). 从我的角度来看,进行此更改将增加重复代码的数量(又称为减少代码重用量)。 Such a change would violate some core precepts of good software engineering. 这样的更改将违反良好软件工程的一些核心原则。

When you say 当你说

"I already have nginx rewrite code set so that website.com/pagename will be accessing website.com/pages/pagename.php" “我已经设置了nginx重写代码,以便website.com/pagename可以访问website.com/pages/pagename.php”

does that mean you are redirecting /pages/pagename.php to /pagename, or that you are simply showing the appropriate content regardless of URL? 这是否意味着您正在将/pages/pagename.php重定向到/ pagename,或者您只是在显示适当的内容而不考虑URL?

If you are redirecting, make sure your rewrites/redirects are 301s and you should be OK. 如果要重定向,请确保您的重写/重定向是301,并且您应该没问题。 Note that a little bit of search authority is lost on 301 redirects, so ideally you wouldn't have to redirect URLs at all. 请注意,在301重定向中失去了一点搜索权限,因此理想情况下,您根本不必重定向URL。 That said, it won't make a huge difference. 也就是说,这不会有太大的不同。

If you are not redirecting and just ensuring that both URLs are showing the same content, make sure you use a canonical tag on URLs that show identical content. 如果您不重定向并且仅确保两个URL都显示相同的内容,请确保在显示相同内容的URL上使用规范标记。

Put this on any duplicate content pages: 将其放在任何重复的内容页面上:

<link rel="canonical" href="http://website.com/pagename" /> 

Unless of course you use www in your url, then use: 除非您当然在网址中使用www,否则请使用:

<link rel="canonical" href="http://www.website.com/pagename" />   

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

相关问题 拒绝直接访问文件夹或文件,但允许index.php访问它 - Deny direct access to a folder or file, but allow index.php to access it 使用 CodeIgniter 阻止对 index.php 的直接访问 - Blocking direct access to index.php with CodeIgniter 拒绝直接访问除index.php之外的所有.php文件 - Deny direct access to all .php files except index.php 禁止直接访问index.php,但将每个URI重定向到index.php / URI - Disable direct access to index.php but redirect every URI to index.php/URI 阻止url直接访问index.php,除非用户单击另一个特定html文件(例如index.html)上的链接 - block url direct access to index.php except when user clicked on the link on another specific html file such as index.html 从index.php访问另一个文件 - Access to another file from index.php 仅当bot要求时才允许直接url访问图像,否则使用.htaccess将url传递到index.php文件 - allow direct url access to image only if requested by bot otherwise pass url to index.php file using .htaccess 没有index.php,Codeigniter无法访问控制器 - Codeigniter cannot access controller without index.php URL中没有index.php的CodeIgniter访问控制器 - CodeIgniter Access controller without index.php in url 限制通过浏览器直接访问 .php 文件,只允许 index.php 访问它们 - Restrict direct access to .php files through browser and allow only index.php to access them
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM