mod_rewrite 来自域的基础
我不确定这是否可行,但我想像这样使用 mod_rewrite:
http://abc.com/something => http://abc.com/script.php?q=something
这不工作:
Options +FollowSymLinks
RewriteEngine on
RewriteRule /(.*)$ /script.php?q=$1
可以做吗?
编辑: 我应该提到,当我使用它时,mod_rewrite 工作正常:
Options +FollowSymLinks
RewriteEngine on
RewriteRule script/(.*)$ /script.php?q=$1
再次编辑: http://emailsms.me/redirect.php?id=abc
使用这个:
RewriteEngine on
RewriteRule ^([A-z]{1,})$ /redirect.php?q=$1
理论上http://emailsms.me/abc 应该输出 abc (它所做的只是回显当前的输入)。但我收到了 404 错误。
更新:似乎Options +FollowSymLinks 导致了这里的问题。如果我将其注释掉,我会收到 404 错误,但是当它在那里并且我输入任何内容(我的意思是任何内容,甚至是 #)时,我会在日志中收到此错误:
[Fri Oct 14 02:20:26 2011] [alert] [client 1.2.3.4] /home/me/redirects/.htaccess: Illegal option #
I'm not sure if this is possible but I want to use mod_rewrite like so:
http://abc.com/something => http://abc.com/script.php?q=something
This doesn't work:
Options +FollowSymLinks
RewriteEngine on
RewriteRule /(.*)$ /script.php?q=$1
Is it possible to do?
Edit:
I should mention mod_rewrite is working fine when I use this for example:
Options +FollowSymLinks
RewriteEngine on
RewriteRule script/(.*)$ /script.php?q=$1
Edit Again: http://emailsms.me/redirect.php?id=abc
Using this:
RewriteEngine on
RewriteRule ^([A-z]{1,})$ /redirect.php?q=$1
So theoretically http://emailsms.me/abc should be outputting abc (all it does is echo the input at the moment). but instead I get a 404 error.
Update: It seems as though Options +FollowSymLinks is causing the problem here. If I comment it out I get a 404 error but when its there and I put anything (I mean anything even a #) I get this error in my logs:
[Fri Oct 14 02:20:26 2011] [alert] [client 1.2.3.4] /home/me/redirects/.htaccess: Illegal option #
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
您可能不希望重写规则中的尾随正斜杠,并且您需要检查请求的文件是否不存在(2个RewriteCond行),否则您将收到 500 服务器错误,因为重写循环(/script.php 将始终匹配 ^(.*)$ 并再次重写)。请注意,如果您没有 /script.php 文件,您将收到 500 错误,因为重写将循环。
Try this:
You probably don't want the trailing forward slash in your rewrite rule, and you need to check that the requested file doesn't exist (the 2 RewriteCond lines) otherwise you'll get a 500 Server error because the rewrite loops (/script.php will ALWAYS match ^(.*)$ and get rewritten again). Note that if you don't have a /script.php file, you'll get a 500 error because the rewrite will loop.
听起来您是从 .htaccess 而不是虚拟主机配置执行此操作。在这种情况下,您必须丢失 RewriteRule 中的第一个 / 。
It sounds like you're doing this from .htaccess, rather than vhost configuration. In that case you must lose the first / in your RewriteRule.
您可以尝试类似的操作:
如您所见,它会因 (.*) 崩溃
You could try something like:
It crashes with the (.*) as you can see