htaccess修改URL

发布于 2024-11-07 09:56:24 字数 485 浏览 0 评论 0原文

我有网址:

http://example.com/at
and want to get:
http://example.com/at/index.php?at=

http://example.com/at/
and want to get:
http://example.com/at/index.php?at=

http://example.com/at/1asSde
and want to get:
http://example.com/at/index.php?at=1asSde

文件夹“at”中的.htaccess

此外,我正在修改位于我一直在尝试的

RewriteEngine On
RewriteRule (.*)$ index.php?at=$1 [QSA,L]

:但稍后在运行该网站的脚本时出现错误。

为了获得正确的结果,我可以尝试什么?

谢谢。

I have the urls:

http://example.com/at
and want to get:
http://example.com/at/index.php?at=

http://example.com/at/
and want to get:
http://example.com/at/index.php?at=

http://example.com/at/1asSde
and want to get:
http://example.com/at/index.php?at=1asSde

Also I am modifying the .htaccess located at the folder 'at'

I've been trying:

RewriteEngine On
RewriteRule (.*)$ index.php?at=$1 [QSA,L]

but am getting errors later when running the script of the site.

What can I try instead in order to get the correct results?

Thanks.

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

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

发布评论

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

评论(4

东北女汉子 2024-11-14 09:56:24

尝试以下操作

RewriteEngine On
RewriteRule ^at/(.*)$ at/index.php?at=$1 [QSA,L]

只要 at/index.php物理位置,您就不需要 at 规则。我鼓励您为 at 创建更好的匹配。例如,如果 (.*) 只能是字母数字,则将其更改为 (\w+)

Try the following

RewriteEngine On
RewriteRule ^at/(.*)$ at/index.php?at=$1 [QSA,L]

You don't need a rule for at so long as at/index.php is a physical location. I would encourage you to create a better match for at. For example change (.*) to (\w+) if it can only be alphanumeric.

屌丝范 2024-11-14 09:56:24

RewriteRule ^at/(.*)$ /at/index.php?at=$1 [QSA,L]

RewriteRule ^at/(.*)$ /at/index.php?at=$1 [QSA,L]

兰花执着 2024-11-14 09:56:24
RewriteEngine On
RewriteRule ^at/(.*)$ index.php?at=$1 [QSA,L]
RewriteEngine On
RewriteRule ^at/(.*)$ index.php?at=$1 [QSA,L]
心舞飞扬 2024-11-14 09:56:24

在重写 URL 之前,您需要确保您尝试获取的资源不存在:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php?at=$1 [QSA, L] #didn't test to make sure this line actually works.

You will want to make sure that the resource you're trying to get doesn't exist before rewriting the URL:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php?at=$1 [QSA, L] #didn't test to make sure this line actually works.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文