skip to Main Content

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


  1. Chosen as BEST ANSWER

    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

    download/FILE-1
    download/FILE-2
    download/FILE-3
    

    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.


  2. Try this :

    RewriteEngine On
    RewriteRule ^download/([a-zA-Z0-9_-]+)$ /ifanydirectory/index.php?down=$1
    

    And you can get variable using $_GET['down'] ifanydirectory is the directory name in which index.php exists relative path from root level, if not applicable simply use /index.php
    do some experiments you’ll get the correct one.

    Login or Signup to reply.
  3. RewriteCond %{REQUEST_URI} ^download/(.*)$ [NC]
    RewriteRule ^(.*)$ index.php?down=$1 [L,QSA]
    

    to catch filename in index.php:

    $filename = $_GET["down"];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search