Reputation: 36
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.
Upvotes: 0
Views: 60
Reputation: 143856
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.
Upvotes: 1