rkaartikeyan
rkaartikeyan

Reputation: 2007

How to Get Current Directory Name in mod_rewrite(.htaccess)

On my servers I use the following rewrite request:

RewriteRule ^profile/([^/]*)/([^/]*)\.html$ /dir_name/kip_dashboard.php?userID=$1 [L]

I am using same .htaccess file in two different location (localhost & server).

Ex.

http://localhost/dir_l/      \\Localhost
http://server.com/dir_ser/   \\Server

How can I get the current directory automatically in .htaccess.

(Ex: RewriteRule ^profile/([^/]*)/([^/]*)\.html$ /{HTTP_DIRECTORY}kip_dashboard.php?userID=$1 [L])

like this.

Upvotes: 2

Views: 2026

Answers (1)

M'vy
M'vy

Reputation: 5774

You can use the RewriteBase directive.

By setting on \\Localhost

RewriteBase /dir_l

and on \\Server

RewriteBase /dir_ser

This will strip the prefix for all next redirection rewrite and happen it when rewrite has been done, so you don't have to specify the directory in the rewrite itself.

See http://httpd.apache.org/docs/current/en/mod/mod_rewrite.html#rewritebase

Upvotes: 1

Related Questions