简体   繁体   中英

.htacces Rewrite Rule to Keep .php File Extensions

I'm upgrading my static website that had .php extensions on the content pages. 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.

The cms has get function to retrieve url structure from the database. Overall it started working fine with .html when i tested. 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."

Here is my .htaccess code which i've used:

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.

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

So basically, content pages with .html are working & .php are not working. But i need my content pages to be with .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. 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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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