使用Apache在PHP上使用2个参数创建一个友好的URL [英] Make a friendly URL with 2 parameters on PHP with Apache

查看:64
本文介绍了使用Apache在PHP上使用2个参数创建一个友好的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我这里有点汤.

我需要创建一个友好的URL.

I need to make a friendly URL.

这是我输入搜索值project_name和版本的URL

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

localhost:8080/demo_webpages_project/retrieval.html

localhost:8080/demo_webpages_project/retrieval.html

这是我提交值的地方

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

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

我想要以下形式的URL

I want the URL in the following form

localhost:8080/demo_webpages_project/download/QT/3.1.2

localhost:8080/demo_webpages_project/download/QT/3.1.2

我尝试使用.htaccess进行此操作,但并未真正找到解决方案

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

以下是.htaccess文件的代码.

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.

谢谢

推荐答案

将此.htaccess放在/demo_webpages_project/中:

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]

这篇关于使用Apache在PHP上使用2个参数创建一个友好的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆