htaccess 帮助

发布于 2024-08-31 23:10:26 字数 380 浏览 3 评论 0原文

我想将其重定向:

foo.com/xxx

... 到此:

foo.com/somepage.php?id=xxx

这就是我的做法:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^/]+)$ http://foo.com/somepage.php?id=$1 [L]

现在的问题是 foo.com 不再工作。 我看不到 foo.com 也看不到 foo.com/index.php

帮助我! :)

I want to redirect this:

foo.com/xxx

... to this:

foo.com/somepage.php?id=xxx

This is how I do it:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^/]+)$ http://foo.com/somepage.php?id=$1 [L]

the problem now, is that foo.com doesn't work any more.
I can't see foo.com neither foo.com/index.php

help me! :)

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

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

发布评论

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

评论(3

将军与妓 2024-09-07 23:10:26
RewriteRule ^/([^/]+)$ /somepage.php?id=$1 [L]

不过要小心,foo.com/1 对 SEO 来说是一个糟糕的举动。

RewriteRule ^/([^/]+)$ /somepage.php?id=$1 [L]

Be careful tho, foo.com/1 is a BAD move on SEO.

梦回梦里 2024-09-07 23:10:26

1)您不需要 RewriteCond 行。它旨在确定您的规则何时适用,而不是请求的哪一部分。

[编辑] 除非,您的 RewriteCond 可以在查询字符串为空时应用此规则。如果是这样的话,那就没什么问题了。

2)我认为你需要在你的规则中包含第一个 / ,如下所示:

RewriteRule ^/([^/]+)$ /somepage.php?id=$1 [L]

[编辑] 你的版本和我的版本都将与你的index.php文件匹配,这可能解释为什么你的网站现在被破坏了。如果您不想匹配 php 文件,您可以添加另一个条件,例如

RewriteCond ${REQUEST_URI} !^.*\.php$

3) 对于这样的规则,在末尾添加 /? 可能会有所帮助(在括号之外,在$),以防他们寻找 foot.com/xxx/,如果您希望它看起来像一个目录,这是有意义的。

1) You don't need the RewriteCond line. It's intended to determine WHEN your rule applies, not WHICH PART of the request.

[EDIT] UNLESS, your RewriteCond is there to make this rule apply whenever the query string is empty. If that's it, then there's nothing wrong with it.

2) I think you need to include the first / in your rule, like this:

RewriteRule ^/([^/]+)$ /somepage.php?id=$1 [L]

[EDIT] Both your version and mine will match your index.php file, which might explain why your site is broken right now. If you don't want to match php files, you could add another condition like

RewriteCond ${REQUEST_URI} !^.*\.php$

3) For a rule like this, it might be helpful to add /? at the end (outside the parens, before the $), in case they look for foot.com/xxx/, which makes sense if you want it to look like a directory.

风铃鹿 2024-09-07 23:10:26

尝试:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(xxx=)$ /somepage.php?id=$1 [L]

当然你没有明确指定xxx=是什么......

Try:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(xxx=)$ /somepage.php?id=$1 [L]

Of course you didn't clearly specify what xxx= is...

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