bonny
bonny

Reputation: 3247

rewriting url with mod_rewrite in .htaccess

hello i have a problem with my site.

i have a site where urls look like:

site.com/page.php

i heard that it is possible to rewrite the url like:

site.com/page

i was looking for that specific rewriterule but i couldnt find anything. all i was found is:

RewriteRule ^$ page.php [L]
RewriteRule ^([a-z]+)/?([0-9]*)/?$ page.php?index=$2 [L]

that does not work.

so if there is someone who could help me out i really would appreciate. thanks a lot.

Upvotes: 0

Views: 120

Answers (3)

Clément Andraud
Clément Andraud

Reputation: 9279

Try :

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)/$ $1 [L]

And/OR don't forget to restart apache ;)

Upvotes: 1

mlishn
mlishn

Reputation: 1667

Place this in your .htaccess

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

Then in any of your urls, you can just do :

http://yoursite.com/about

Instead of :

http://yoursite.com/about.php

and it will still load

Upvotes: 2

pankar
pankar

Reputation: 1701

Try this

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Upvotes: 2

Related Questions