重写URL与htaccess的重写、URL、htaccess

2023-09-02 10:03:56 作者:四海八荒第一小短腿

我需要做的是改变对我的网站的链接,例如从

What I need to do is change the links on my website, for example from

www.mywebsite.com/index.php

www.mywebsite.com/index.php

www.mywebsite.com/index.php?action=about_us

www.mywebsite.com/index.php?action=about_us

www.myswebsite.com/index.html

www.myswebsite.com/index.html

www.myswebsite.com/about_us.html

www.myswebsite.com/about_us.html

有人告诉我的的htaccess 的来达致这和我presume这是实现了与某种常规EX pression。

I was told htaccess was used to acheive this and I presume this is achieved with some sort of regular expression.

我怎样才能实现这个结果?

How can I achieve this result?

推荐答案

打开重写引擎。该重写规则将获取的页面中的第二个参数时,第一个参数被调用。因此, www.myswebsite.com/about_us.html 将加载 www.mywebsite.com/index.php?action=about_us ,但在地址栏中的URL仍将 www.myswebsite.com/about_us.html 。该 [NC] 在刚刚结束使得它不区分大小写。

Turn on the rewrite engine. The RewriteRule will fetch the page in the second parameter when the first parameter is called. So www.myswebsite.com/about_us.html will load www.mywebsite.com/index.php?action=about_us, but the URL in the address bar will still be www.myswebsite.com/about_us.html. The [NC] at the end just makes it case insensitive.

RewriteEngine On
RewriteRule ^/about_us.html$ index.php?action=about_us [NC]

更多信息: http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html

More info: http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html