静态 伪静态 优先级
有何好的方案解决静态、伪静态的优先级问题?系统: Linux Apache PHP/5.2.17
现在服务器上用.htaccess重写地址做伪静态,用了缓存。但是还是经常超出空间商的cpu limit,最近已经两次被空间商强制停机了。
现在想把大部分的页面改成纯静态,只有分页还保留伪静态。
现在希望能够在“纯静态html”页面存在的情况下直接链接到“纯静态html”页面,“纯静态html”页面不存在的情况下就用伪静态。
但是,我们知道在有伪静态规则的规范下是无法访问到“纯静态”页面的,始终会被链接到相应的php页执行。
查询 百度,看到有说用不同后缀来区分纯静态和伪静态,如:.htm .html
这样是可以达到目的,但是要修改很多模板里的.html,很麻烦,在这里想请问大神们有没有更好的解决方案。
望大神们不吝赐教啊!
拜谢了!
回复讨论(解决方案)
在用.htm .html不同扩展名 来解决 优先级问题,会带来另外一个问题,那就 状态码302问题
302对搜索引擎不友好,会引起搜索引擎的误会(有URL规范化及网址劫持的问题,可能被搜索引擎判为可疑转向,甚至认为是作弊【摘自xxx博客】)
.htm 做伪静态,当用户点击 xxx/xx.htm 进来后 相应的 xx.php会执行, 先判断xx.html是否存在且没有过期,如果不是则读取数据和模板生成相应的xx.html页,如果是则直接location到xx.html。 就是这个location转向,产生了302错误,所以......
所以问大神们 , 有没有好的解决方案?
.htaccess重写地址应该可以解决。如果没找到就下一条规则。实在不行,对404写一下规则。
不管怎么样,你要做判断是否存在静态页面,就一定要用到PHP程序。总之,apache不管这个事。
if(!file_exists('xxx/xx.htm')||(time()-filemtime('xxx/xx.htm'))>3600)){
//代码生成自动程序,保存为xxx/xx.htm
}else{
//file_get_contents(xxx/xx.htm);
}
还是多从源码下功夫吧,减少include,require,合理运用unset();合并相同的代码为function()调用,等等。
此外,可以考虑换空间。
1、如果没有后缀,显然就不是真静态。再麻烦也是需要修改的
更何况,伪静态页面的 url 应该是由函数产生的,如果你不是这样做的,那么就应该坚决改正过来
2、常见的重写规则中都有
RewriteCond %{REQUEST_FILENAME} !-f
如果文件存在,就直接访问文件,不进行下面的RewriteRule。
3、如果真实存在的 .htm 都还要经 php 处理的话,那我就不知道你的“静态”是指什么了
感谢 徐老师
一直不知道
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
的作用
现在总算知道了
谢谢! 结贴!

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version
