1

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

anubhava
  • 761,203
  • 64
  • 569
  • 643
hal9000
  • 201
  • 5
  • 25

2 Answers2

1

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]
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

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'
?>
Ajay Kumar Ganesh
  • 1,838
  • 2
  • 25
  • 33
  • Hello I tried the following too #3 #RewriteRule /download.php/(.*)$ /download.php/download.php?project_name=$1&version=$2 #4 RewriteRule ^demo_webpages_project/download.php/([a-z_]+)/([a-z0-9_-]+)$ /demo_webpages_project/download.php?project_name=$1&version=$2 – hal9000 Sep 21 '16 at 19:08
  • Neither work. I am getting these errors Notice: Undefined index: project_name in C:\Apache24\htdocs\demo_webpages_project\download.php on line 38 Notice: Undefined index: version in C:\Apache24\htdocs\demo_webpages_project\download.php on line 39 – hal9000 Sep 21 '16 at 19:09