简体   繁体   中英

Getting Internal server error for RewriteRule -.htaccesss

I am trying to write the RewriteRule for the following scenario

When I hit the url: localhost/ example

it needs to load the example.php file which is in sub folder( pages )

Folder structure:

- pages
- example.php
- styles
- scripts
- index.php

my .htaccess file is as follows

RewriteEngine on
RewriteRule ^(.*)$ pages/$1.php

but I am getting

500 Internal server error

Anyone please help me with this scenario.

Your rewrite rules are probably looping. Add a condition to prevent this from happening:

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/pages/$1.php -f
RewriteRule ^(.*)$ /pages/$1.php [L]

Since the rewrite engine loops until the URI stops changing, the (.*) matches everything, including /pages/whatever . So the URI keeps getting /pages/ appended to the front of the URI.

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