简体   繁体   English

HTML / PHP链接结构

[英]HTML/PHP link structure

I know this question was probably already answered but I just don't know what to search for, it would be helpful to at least know what I am looking for. 我知道这个问题可能已经回答,但我只是不知道要搜索什么,至少知道我在寻找什么会有所帮助。

So what I'd like to do is have link in which there is a number of article to display, like this: 所以我想做的是有链接,其中有很多文章要显示,如下所示:

www.mywebpage.com/store/article/[article no.]

Where article no. 文章没有。 is just plain number(for example 12345). 只是普通数字(例如12345)。 I'd like to read it in my php script and I'd like the link to be without the ?article=[article no.] which is generated in get method. 我想在我的php脚本中阅读它,我希望链接没有在get方法中生成的?article = [article no。]。

*mod_rewrite* is the thing you want. * mod_rewrite *是你想要的东西。 In your PHP script, use var_dump($_GET) to see the HTTP request argument. 在PHP脚本中,使用var_dump($ _ GET)查看HTTP请求参数。

What you need to do is redirect script flow to the runnable file handeling the articles. 您需要做的是将脚本流重定向到handeling文章的runnable文件。 You can achieve this with .htaccess files and mod_rewrite if you are using Apache. 如果使用Apache,可以使用.htaccess文件和mod_rewrite实现此目的。

RewriteEngine On
RewriteRule ^store/article/([0-9]+)$ myscript.php?article=$1

This will redirect the script flow internally so that myscript.php sees it as if you accessed myscript.php?article=123 for article number 123 but you will be able to access that with the link store/article/123 . 这将在内部重定向脚本流,以便myscript.php看到它就好像你访问了文章编号123的myscript.php?article=123 ,但是你可以通过链接store/article/123访问它。

Thus you can access the article number in myscript.php with $_GET['article'] . 因此,您可以使用$_GET['article']访问myscript.php的文章编号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM