htaccess 帮助
我想将其重定向:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不过要小心,
foo.com/1
对 SEO 来说是一个糟糕的举动。Be careful tho,
foo.com/1
is a BAD move on SEO.1)您不需要 RewriteCond 行。它旨在确定您的规则何时适用,而不是请求的哪一部分。
[编辑] 除非,您的 RewriteCond 可以在查询字符串为空时应用此规则。如果是这样的话,那就没什么问题了。
2)我认为你需要在你的规则中包含第一个 / ,如下所示:
[编辑] 你的版本和我的版本都将与你的index.php文件匹配,这可能解释为什么你的网站现在被破坏了。如果您不想匹配 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:
[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
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.尝试:
当然你没有明确指定xxx=是什么......
Try:
Of course you didn't clearly specify what xxx= is...