natanel97 natanel97 - 3 months ago 30
Apache Configuration Question

htaccess: friendly url - trailing slash and "fake subdirectories"

I want to make fake-subdirectories with htaccess (

fakefolder/forget-password
with rewrite mod), but it doesn't really working for me...

I have this url:

parent-directory/index.php?version=1&do=forget-password&email=example@domain.com&token=85085ab92fcfd5dada280c73f7f494ec


*
note: the 'email' variable is being verified with mysql, and I use
filter_var
in case the value is an email so it can be also username instead (
email=username
).
parent-directory
is a real directory.
version
is dynamic, and can be 2 or 3 or string, and show a different result, so in this case
version=1
is
fakefolder
.
version=2
and any other value can be anything else (
fakefolder2
)

and this
htaccess
code:

Options +FollowSymLinks -MultiViews
RewriteEngine On

# Set configuration file
php_value auto_prepend_file configuration.inc.php

# Start Rewriting
RewriteBase /parent-directory/

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^fakefolder$ index.php?version=1 [QSA,L]


if I try to make something like this:
RewriteRule ^([a-z])$/forget-password$ index.php?version=$1&do=forget-password [QSA,L]
it's not working, or showing 404

Is it possible? (if yes, then can it be multileveled? e.g.
index.php?version=1&do=forget-password&email=example@domain.com -> ([a-z])$/forget-password/username
instead of
fakefolder/forget-password?email=...
)?

Please excuse my english and thanks a lot.

Answer

Try these rules:

# Set configuration file
php_value auto_prepend_file configuration.inc.php

Options +FollowSymLinks -MultiViews
RewriteEngine On
# Start Rewriting
RewriteBase /parent-directory/

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([\w-]+)/forget-password/([\w-]+)/?$ index.php?version=$1&do=forget-password&email=$1 [QSA,L,NC]

RewriteRule ^([\w-]+)/forget-password/?$ index.php?version=$1&do=forget-password [QSA,L,NC]

RewriteRule ^fakefolder/?$ index.php?version=1 [QSA,L,NC]
Comments