one2som
one2som

Reputation: 33

.htaccess rewrite rules for two or more PHP files

right now I have .htaccess file to rewrite url for my profile.php (root directory)

    RewriteEngine On
    RewriteCond %(REQUEST_FILENAME) !-f
    RewriteCond %(REQUEST_FILENAME) !-d
    RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1

This codes transform http://127.0.0.1/projects/webproject/profile.php?username=sarah into http://127.0.0.1/projects/webproject/sarah

Situation: Say, I have "update_availability.php" (root directory), and access it with this format http://127.0.0.1/projects/webproject/update_availability.php?month=03&day=18&year=2014.

I want to change the URL into http://127.0.0.1/projects/webproject/update_availability.php/03/18/2014.

What I want to know:

  1. is it possible to have one .htaccess file (root directory) and rewrite rule for other php file?
  2. How can I transform http://127.0.0.1/projects/webproject/update_availability.php?month=03&day=18&year=2014 into http://127.0.0.1/projects/webproject/update_availability.php/03/18/2014.

I am new to .htaccess. I will appreciate any help.

Upvotes: 3

Views: 95

Answers (1)

anubhava
anubhava

Reputation: 785128

You can use:

RewriteEngine On
RewriteBase /webproject/

RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^([\w-]+)$ profile.php?username=$1 [L,QSA]

RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(update_availability(?:\.php)?)/([0-9]+)/([0-9]+)/([0-9]+)/?$ $1?month=$2&day=$3&year=$4 [L,QSA,NC]

Upvotes: 1

Related Questions