PHP Question

How to use RewriteRule like WordPress and Drupal

I have a website with an include script that will have a various number of variables.

Here are some of the types of URLs and variables:

Main page: index.php

Login page: login.php (redirects to index.php after login).

Logout page: logout.php (redirects to login after logout).

Profile page: index.php?id=profile

Users password page: index.php?id=profile&sub=password

And some pages even has more variables in the URL. I want to use RewriteRules to be able to get nice URLs like this: (base) (profile page) (password page) (use variables in the URL)

How can I do this in the .htaccess-file? The site is not the root on the domain, but a couple of folders down.

Answer Source

.htaccess rules apply to its container directory and all of its subdirs. This might be a good starting point:

<IfModule mod_rewrite.c>
    #Removing .php file extension.
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php

Or you might want to remove the index.php's GET parameters from within url:

<IfModule mod_rewrite.c>
    #removing GET parameters.  
    RewriteRule ^index/([^/\.]+)/?$ index.php?id=$1 [L]

Read more:

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