skip to Main Content

So I am in a bit of a soup here.

I need to make a friendly URL.

This is the URL where I enter the search values project_name and version

localhost:8080/demo_webpages_project/retrieval.html

This is where it takes me to on submitting the values

localhost:8080/demo_webpages_project/download.php?project_name=QT&version=3.1.2

I want the URL in the following form

localhost:8080/demo_webpages_project/download/QT/3.1.2

I tried doing this using .htaccess but not really finding a solution

The following is the code for the .htaccess file.

<IfModule mod_rewrite.c>
#Turn the engine on
RewriteEngine on

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

#attempt1
#RewriteRule ^(.*)/$ download.php?project_name=$1&version=$1
#RewriteRule ^/(.*)$ download.php?version=$1

#attempt2
#RewriteRule ^(.*)/(.*)$ download.php?project_name=$1&version=$2 [L,NC,QSA]
#RewriteRule ^(.*)$ download.php?version=$1

</IfModule>

I would be really grateful if someone could help me out with this. This is the first time I am working on something on this and am lost.

Thanks

2

Answers


  1. According to this article, you want a mod_rewrite (placed in an .htaccess file) rule that looks something like this:

    RewriteEngine on 
    RewriteRule ^/news/([0-9]+).html /news.php?news_id=$1
    

    And this maps requests from

    /news.php?news_id=63
    

    to

    /news/63.html
    

    Another possibility is doing it with forcetype, which forces anything down a particular path to use php to eval the content. So, in your .htaccess file, put the following:

    <Files news>
        ForceType application/x-httpd-php
    </Files>
    

    And then the index.php can take action based on the $_SERVER[‘PATH_INFO’] variable:

    <?php
        echo $_SERVER['PATH_INFO'];
        // outputs '/63.html'
    ?>
    
    Login or Signup to reply.
  2. Have this .htaccess inside /demo_webpages_project/:

    Options -MultiViews
    RewriteEngine on
    RewriteBase /demo_webpages_project/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/([^/]+)/?$ download.php?project_name=$1&version=$2 [L,QSA]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search