阿帕奇mod-rewrite简单的重定向 [英] Apache mod rewrite simple redirect

查看:147
本文介绍了阿帕奇mod-rewrite简单的重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想请求我的网站的工作如下:

I want requests to my site to work as follows:

http://example.com/ 会拉起index.php文件(当前默认的行为)理想而不显示的index.php

http://example.com/ would pull up the index.php file (the current default behavior) ideally without displaying the index.php

http://example.com/foo.php 会拉起foo.php的是预计

http://example.com/foo.php would pull up foo.php as would be expected

http://example.com/blerg 会重定向到的 http://example.com/bar.php?$c$c=blerg

我有以下的重写规则,现在

I have the following rewrite rules right now

    RewriteRule ^/(.*\.(php|html|htm|css|jpg))$ /$1 [NC,L]
    RewriteRule ^/(.*)$ /bar.php?code=$1 [NC,L]

几乎工程,除 http://example.com/ ,而不是拉的index.php高达bar.php

which almost works, except http://example.com/ pulls up bar.php instead of index.php

理想我就不必在第一条规则每一个可能的文件扩展名,我宁愿它只是检测是否它是一个实际的文件。

Ideally I wouldn't have to have every possible file extension in the first rule, I would rather it just detect if it's an actual file.

推荐答案

研究发现,有效的解决方案。

Found a solution that works

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([^.]+)$ /bar.php?code=$1 [QSA,L]


http://example.com/ directs to index.php properly (without showing index.php)
http://example.com/abc directs to bar.php?code=abc
http://example.com/foo.php operates normally.

这篇关于阿帕奇mod-rewrite简单的重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆