search
HomeBackend DevelopmentPHP Tutorial有何好的方案解决静态、伪静态的优先级问题?

静态 伪静态 优先级

有何好的方案解决静态、伪静态的优先级问题?

系统: 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
的作用

现在总算知道了

谢谢! 结贴!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools