有三个动态参数重写URL重写、参数、动态、URL

2023-09-02 09:59:57 作者:男人不能惯,越惯越混蛋

我在我的网站的工作,其中URL是这样的:

I am working on my website where URL is something like:

http://mywebsite.com/series.php?sid=1&part=1&name=Introduction%20to%20HTML

我曾在我的htaccess的规则是:

I have tried a rule in my htaccess which is:

RewriteRule ^([^/]+)/([^/]+)/([^.]+).html$ /series.php?sid=$1&part=$2&name=$3

为了在形式重写网址:

http://mywebsite.com/1/1/Introduction to html.html

不幸的是,它不是为我工作。

Unfortunately, it is not working for me.

请别人帮我整理出来的问题。我也喜欢它,如果有人让我明白它是如何工作。 我是新手对的.htaccess。 在上面的规则,我可以看到三个不同的部分,如:

Please someone help me in sorting out the issue. I would also love it if someone makes me understand how it worked. I'm newbie for .htaccess. In above rule, I can see three different parts like:

1st part: ^([^/]+)
2nd Part: ([^/]+)
3rd part: ([^.]+).html$

这些三个部分由反斜杠分离。他们是如何工作和如何使用超过3让同样的重写URL的形式说,4个或5个参数,小于3样2参数?

These three parts are separated by backslash. How they work and how can I utilize the same Rewrite URL form for more than 3 let say 4 or 5 parameters and less than 3 like 2 parameters?

感谢您!

推荐答案

您的规则是正确的,只是添加标志,结束了统治和确保的.htaccess和mod_rewrite的通过Apache的配置被启用。

Your rule is correct, just add L flag to end the rule and make sure .htaccess and mod_rewrite are enabled through Apache config.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteRule ^([^/]+)/([^/]+)/([^.]+).html$ /series.php?sid=$1&part=$2&name=$3 [L,NC,QSA]