Reputation: 1627
I am currently trying to write a rewrite rule. I want to simplify the entered URL so that it will always use the index. The input url would be www.example.com/home.php
and would be rewritten to www.example.com/index.php?r=page/home
.
I wrote this .htaccess
file:
RewriteEngine On
RewriteRule ^([^/]*)\.php$ /index.php?r=page/$1 [L]
This configuration unfortunately gives me an error 500. I can understand that it is caused by the fact that if I enter index.php
for instance, apache will not know if it must use the index.php
file or use the rewritten url index.php?r=page/index
.
Is it possible to accomplish this kind of rewriting rule with apache? If so, how can I fix my error 500?
Edit: Please note that the RewriteRule works fine if I change the extension .php
to anything else such as .html
, as so: RewriteRule ^([^/]*)\.html$ /index.php?r=page/$1 [L]
Upvotes: 3
Views: 3683
Reputation: 77
you can also try with this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?r=page/$1 [L]
Upvotes: 1
Reputation: 19016
You have two possibilities.
First one
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule ^([^/]+)\.php$ /index.php?r=page/$1 [L]
Second one
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /([^/]+)\.php
RewriteRule ^.*$ /index.php?r=page/$1 [L]
Upvotes: 1