2012-12-18 67 views
0

我有一个文件夹,并在该文件夹中的htaccess文件的网站。对于该文件夹中的index.php文件,我想重写这个URL一定参数查询字符串,使打字:htaccess - 重写网址,使查询字符串不错

www.example.com/myfolder/myparameter 

的行为是这样的(即让$_GET['parameter'] = 'myparameter'在我的代码)

www.example.com/myfolder/index.php?parameter=myparameter 

我已经看过StackOverflow上的很多问题,但还没有设法得到这个工作。我的代码到目前为止是

RewriteEngine on 
RewriteCond %{QUERY_STRING} ^(.*) [NC] 
RewriteRule ^$ %0 [QSA] 

但这根本不起作用。

回答

1

请使用此代码

RewriteEngine on 
RewriteRule (.*) index\.php?parameter=$1 [L,QSA] 
+0

非常感谢,这个工程。但是,脚本,样式表和图片不再有效。这些网址的网址为www.example.com/myfolder/_images/image.png,www.example.com/myfolder/_scripts/script.js。你能帮我解决这些问题吗? – Will

+0

请使用此 RewriteRule!\。(js | gif | jpg | png | css | txt | eot | woff | ttf)$ - [L] – somasundaram

0
RewriteEngine on 
RewriteRule (^.*/)([^/]+)$ $1index\.php?parameter=$2 [L,QSA] 

更新
对不起使用@ somasundaram的答案。每目录的.htaccess重写规则失去目录前缀:

当使用.htaccess中的重写引擎文件的每个目录前缀(始终是为特定的目录相同)的重写规则模式将被自动删除匹配并在任何相对(不以斜杠或协议名称开头)替换遇到规则集结束后自动添加。有关哪些前缀将添加回相关替换的更多信息,请参阅RewriteBase指令。

(从apache docs

+0

这似乎不起作用,给出“未找到页面” – Will

+0

@请参阅我的更新。正如你所发现的,somasundaram的答案是要走的路! – foundry