我如何重写 URL,例如

发布于 2024-10-01 16:25:04 字数 542 浏览 1 评论 0原文

我需要重写我的网址,例如

http://www.site.com/profile/ -> profile.php
http://www.site.com/settings/ -> settings.php

配置文件的另一个词和 settinhs 是指向 user.php 示例的链接

如果我推送 http,则 ://www.site.com/giffary/ - 它是指向 user.php?name=giffary 的链接,

但是当我推送 http://www.site.com/profile/ - 它是指向 profile.php 而不是 user.php 的链接。

我怎样才能写.htaccess文件

谢谢:)

I need to rewrite my web URL such as

http://www.site.com/profile/ -> profile.php
http://www.site.com/settings/ -> settings.php

and another word of profile and settinhs is link to user.php

example,

if I push http://www.site.com/giffary/ - it's link to user.php?name=giffary

but when i push http://www.site.com/profile/ - it's link to profile.php not user.php.

how can i write .htaccess file

thank you :)

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

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

发布评论

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

评论(1

淡紫姑娘! 2024-10-08 16:25:04

显然,您需要为此使用 mod_rewrite 。我还没有测试过,但是这个配置应该可以工作:

RewriteEngine On
RewriteBase /

# Ignore URLs that point to files/directories that actually exist.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Special rewrites
RewriteRule ^/profile/?$ /profile.php [L]
RewriteRule ^/settings/?$ /settings.php [L]

# User profile rewrites
RewriteRule ^/([^/]+)/?$ /user.php?name=$1 [L]

You will need to use mod_rewrite for this, obviously. I have not tested it, but this config should work:

RewriteEngine On
RewriteBase /

# Ignore URLs that point to files/directories that actually exist.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Special rewrites
RewriteRule ^/profile/?$ /profile.php [L]
RewriteRule ^/settings/?$ /settings.php [L]

# User profile rewrites
RewriteRule ^/([^/]+)/?$ /user.php?name=$1 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文