简体   繁体   English

.htacces重写规则以保留.php文件扩展名

[英].htacces Rewrite Rule to Keep .php File Extensions

I'm upgrading my static website that had .php extensions on the content pages. 我正在升级在内容页面上具有.php扩展名的静态网站。 I've created my own simple cms which will start retrieving data from mysql database from now on, keeping the url structure same as the old once. 我创建了自己的简单cms,从现在开始将开始从mysql数据库中检索数据,并保持url结构与旧的相同。

The cms has get function to retrieve url structure from the database. cms具有get功能,可从数据库中检索url结构。 Overall it started working fine with .html when i tested. 总的来说,当我测试时,它可以与.html一起正常工作。 But when i change the .html extension to .php in my .htaccess code the content pages starts reflecting "Internal Server Error. The server encountered an internal error or misconfiguration and was unable to complete your request." 但是,当我在.htaccess代码中将.html扩展名更改为.php时,内容页面开始反映“内部服务器错误。服务器遇到内部错误或配置错误,无法完成您的请求。”

Here is my .htaccess code which i've used: 这是我使用过的.htaccess代码:

RewriteBase / 
Options +FollowSymLinks 
RewriteEngine On
RewriteRule ^([^?]*).php$ content.php?pid=$1

Perhaps there is a conflict, here is the code with .html extension that actually works fine. 也许有冲突,这是带有.html扩展名的代码,实际上可以正常工作。

RewriteBase / 
Options +FollowSymLinks 
RewriteEngine On
RewriteRule ^([^?]*).html$ content.php?pid=$1

So basically, content pages with .html are working & .php are not working. 因此,基本上,带有.html的内容页面正常工作,而.php则无法工作。 But i need my content pages to be with .php 但是我需要我的内容页面与.php一起使用

Please help. 请帮忙。 Thanks in advance... :) 提前致谢... :)

Since matching pattern and target URI both have php extension therefore it is causing looping and hence 500 error for you. 由于匹配的模式和目标URI都具有php扩展名,因此会导致循环,从而为您带来500错误。 You can use a different regex and an extra condition to avoid looping: 您可以使用其他正则表达式和其他条件来避免循环:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)\.php$ content.php?pic=$1 [L,QSA,NC]

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM