可有人提醒我在正确的方向上使用mod_rewrite?我在、正确、mod_rewrite

2023-09-02 00:50:04 作者:不懂感情狗

我有点新本,但我努力学习。我知道,在PHP中,我们可以在?ID =东西结尾的网址,但在我看来,一些网站在做,它只是斜杠。这是使用PHP可能吗?只见这些 questions这似乎是说,这是可能的,但我还没有破解它。

I am a bit new to this but I am trying to learn. I know that in PHP we can have a URL that ends in ?id=something but it seems to me that some websites are doing it just forward slashes. Is this possible using PHP? I saw these questions that seem to say it is possible but I haven't cracked it yet.

有人能促使我朝着正确的方向的mod_rewrite ?我想改变以下网址

Can someone prompt me in the right direction for mod_rewrite? I would like to change the following URL

http://www.example.com/all-products/?onsale=true&topic=health&item=adaaos45

http://www.example.com/all-products/items-on-sale/health/adaaos45

您可以点我到正确的方式?

Can you point me into the right way?

推荐答案

您要找的是Apache的URL重写。

What you are looking for is Apache Url Rewriting.

我会打破它下来一点给你帮助你理解,我们首先要清楚一点正则表达式

I will break it down a bit for you to help you understand, it helps to know a bit of regex.

有很多在这里的答案是讨论的方法,但总括起来,你需要做三件事情。

there are a lot of answers here that discuss the method, but to sum it all up, you need to do three things.

# Switch on URL Rewriting
# Choose the URL that you want to display  
# Point it to the true URL that gives the information.

Options FollowSymLinks
RewriteEngine On

RewriteRule ^all-products/items-on-sale/health/adaaos45/?$ all-products/?onsale=true&topic=health&item=adaaos45 [NC,L]

现在当然,如果你想匹配任何结果的变量,你需要匹配的正则表达式的话,并记住它,并用它在该行的最后一部分。但是,这应该让你开始理解正在发生的事情。

Now of course, if you would want to match any results for the variables, you need to match the word in regex, and remember it, and use it in the last part of the line. But this should get you started on understanding what is going on.

通过这个code在你的.htaccess,浏览到

With this code in your .htaccess, browsing to

http://www.example.com/all-products/items-on-sale/health/ adaaos45

会告诉你,这个页面上显示的内容。

will show you the content that displays on this page.

http://www.example.com/all-products/?onsale=true&topic=health&item=adaaos45