views:

304

answers:

1

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:

url.com/my/site/ (base)
url.com/my/site/profile/ (profile page)
url.com/my/site/profile/password/ (password page)
url.com/my/site/profile/password/variable1/variable2/variable3/ (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.

+2  A: 

The .htaccess will effect on its container directory and the container childs directories by default. The code below might be a good start point.

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

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]
</IfModule>

read more:

Sepehr Lajevardi