mod_rewrite指向site.com/something到index.php?values = something

时间:2012-08-06 21:42:35

标签: php mod-rewrite

(我可能是个白痴,似乎在OSX上的Apache默认情况下没有启用.htaccess。)

我知道那里有很多mod_rewrite问题,但我不能让我的权利得到解决,而其他任何事情似乎都无法覆盖它。

我想做的就是重定向

www.url.com/something

www.url.com/something/anything/more

www.url.com/index.php?values=something

www.url.com/index.php?values=something/anything/more

没有比这更好的了(我会放弃一些关于忽略gif / jpg / png的东西,稍后再添加www等) - 所有处理的东西/任何/更多都将在PHP中完成。

但是,我无法做到这一点。任何提示/资源或任何刚刚设法做到这一点的人?知道我曾经把它完美地完美但几年前丢失了那段代码,这更令人沮丧。

2 个答案:

答案 0 :(得分:1)

RewriteEngineOn
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d    
RewriteRule ^(.*)$ /index.php?values=$1 [L]

请注意,如果您尝试在.htaccess文件中执行此操作,则需要在Apache主机配置文件中为相关目录设置AllowOverride On,当然需要启用mod_rewrite模块。

此规则将忽略实际存在的任何实际文件或目录(即图像)的重定向(包括index.php)。

答案 1 :(得分:1)

这非常简单,至少在你要求的内容但是基本上你需要使index.php passthrough(所以你不要将index.php 重写为 index.php),然后主要改写。

RewriteEngine On
RewriteRule index.php - [L]

# your conditions here
RewriteRule ^/?(.*)$ /index.php?values=$1 [L]

# your conditions here

添加您想要排除重写的条件