使用 htaccess 重写 url

发布于 2024-09-26 02:22:58 字数 347 浏览 1 评论 0原文

我需要做的是更改我网站上的链接,例如

www.mywebsite.com/index.php

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

www.myswebsite.com/index.html

www.myswebsite.com/about_us.html

我被告知 htaccess 用于实现此目的,我认为这是通过某种正则表达式实现的。

我怎样才能达到这个结果?

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?action=about_us

to

www.myswebsite.com/index.html

www.myswebsite.com/about_us.html

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

氛圍 2024-10-03 02:22:58

您有

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

并且您希望

www.myswebsite.com/about_us.html

在您的 .htaccess 文件中添加一行到该文件的末尾:

redirect /about_us http://www.myswebsite.com/about_us.html

http://affiliate-minder.com/internetmarketing/ using-htaccess-file-for-affiliate-link-redirects/

PK

you have

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

and you want

www.myswebsite.com/about_us.html

in your .htaccess file add a line to the end of this file:

redirect /about_us http://www.myswebsite.com/about_us.html

voila

http://affiliate-minder.com/internetmarketing/using-htaccess-file-for-affiliate-link-redirects/

PK

红焚 2024-10-03 02:22:58

打开重写引擎。当调用第一个参数时,RewriteRule 将获取第二个参数中的页面。因此 www.myswebsite.com/about_us.html 将加载 www.mywebsite.com/index.php?action=about_us,但地址栏中的 URL 仍将是www.myswebsite.com/about_us.html。最后的 [NC] 只是使其不区分大小写。

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

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

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]

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

北城挽邺 2024-10-03 02:22:58
CheckSpelling on
Options -Indexes
Options +FollowSymlinks

DirectoryIndex index.php

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$\.html /index.php?action=$1 [L,QSA]

从那里,您可以使用 index.php 进行导航,或者仅显示内容

CheckSpelling on
Options -Indexes
Options +FollowSymlinks

DirectoryIndex index.php

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$\.html /index.php?action=$1 [L,QSA]

and from there, you could use index.php to either navigate, or just display the content

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文