Martney Acha Martney Acha - 1 year ago 95
PHP Question

URL .htaccess in php

Do anyone can give some advice on how to do

URL for my php page

I have this URL

What I need is this URL

What I do is

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

But it / "Backslash" is reading for another directory, any idea how to fix this ?

Answer Source

You can use these rules:

RewriteEngine On

# Forward /profile/8 to /profile.php/8
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^([\w-]+)/([\w-]+)/?$ $1.php/$2 [L]

# Forward /profile to /profile.php
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteCond is to ensure corresponding .php exists.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download