I’m having some trouble using rewrite engine to achieve my goal with friendly url.
Basically I have the following structure:
– index.php
– down
– index.php
My links in main index are something like this:
download/index.php?down=FILENAME
I would like it to rewrite something like
/download/FILE-NAME ( while pointing for the index.php inside download folder ).
I would like my links in first index could be used as well /download/FILE-NAME
My actual code:
RewriteEngine On
RewriteRule download/^([a-zA-Z0-9_-]+)$ index.php?down=$1
Can anyone help me achieving this? I’m constantly getting error due to I can’t do it right.
After that, how can I get the the variable $1 after transform to seo friendly urls? I will have download/FILE-NAME and I need with PHP get the info from FILE-NAME.
So basically in the main index.php I would have a link like /download/FILE-NAME that will open the down/index.php file with the FILE-NAME ( staying something like.
3
Answers
Maybe I've not explain it well because it doesn't work as it's supposed.
I've edited the main question but try to explain better here.
I have a main index.php with links that would be
That links should open the folder down/index.php?down=FILE-NAME. Isn't supposed that anyone can access "down" folder directly, so I would like to transform links in my main index.php like /down/index.php?down=FILE-NAME to something like /download/FILE-NAME.
Try this :
And you can get variable using
$_GET['down']
ifanydirectory
is the directory name in whichindex.php
exists relative path from root level, if not applicable simply use/index.php
do some experiments you’ll get the correct one.
to catch filename in index.php: