使用mod_rewrite将.html重写为.php [英] Rewrite .html to .php using mod_rewrite

查看:102
本文介绍了使用mod_rewrite将.html重写为.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  RewriteCond%{DOCUMENT_ROOT} $ 0!-f 
我有一个重写条件和规则。 RewriteRule ^ [^ *] + $ index.php [L]

我需要将<$ c在%{DOCUMENT_ROOT} $ 0 中带有 .php 的$ c> .html p>

原因是,我正在将我的url重写为 .html ,但是当此文件检查现有文件时,它会失败至%{DOCUMENT_ROOT} $ 0 查找文件 thefile.html



我需要它寻找 thefile.php

解决方案

<要重写 .html 扩展到现有的 .php 具有相同名称的文件,请尝试使用此规则而不是您的有:

  RewriteCond%{REQUEST_FILENAME}!-f 
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule ^(。*)\.html $ $ 1.php?%{QUERY_STRING} [L]

RewriteCond%{REQUEST_FILENAME}!-f
RewriteRule ^。* $ index.ph p [L]

你只是将任何不存在的文件重写为index.php


I have a rewrite condition and rule which is.

RewriteCond %{DOCUMENT_ROOT}$0 !-f
RewriteRule ^[^*]+$ index.php [L]

I need to replace .html with .php in %{DOCUMENT_ROOT}$0.

The reason is, I am rewriting my url's to .html but when this file checks for an existing file it fails due to %{DOCUMENT_ROOT}$0 looking for file thefile.html,

I need it to look for thefile.php.

解决方案

For rewriting .html extensions to existing .php files with the same name, try this rule instead of what you had:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ $1.php?%{QUERY_STRING} [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [L]

What you have just rewrites any non-existent file to index.php

这篇关于使用mod_rewrite将.html重写为.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆