使用htaccess将目录传递给GET参数而无需重写url [英] Using htaccess to pass directories to GET parameters Without rewriting url

查看:59
本文介绍了使用htaccess将目录传递给GET参数而无需重写url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想传递(而不是重定向)这样的内容:

I would like to pass (not redirect) something like this:

http://www.example.com/(带有/可选) 传递给脚本 http://www.example.com/index.php

http://www.example.com/ (with / optional) passed to the script http://www.example.com/index.php

http://www.example.com/foo/(带有/可选) 传递给脚本 http://www.example.com/index.php?nav=foo

http://www.example.com/foo/ (with / optional) passed to the script http://www.example.com/index.php?nav=foo

http://www.example.com/foo/bar (带有/可选) 传递给脚本 http://www.example.com/index.php?nav=foo& ; subnav = bar

http://www.example.com/foo/bar (with / optional) passed to the script http://www.example.com/index.php?nav=foo&subnav=bar

此外,我想将子域 http://testumgebung.example.com 传递给 http://www.example.com/testumgebung.php .

Furthermore I would like to pass the subdomain http://testumgebung.example.com to http://www.example.com/testumgebung.php with the same parameters as above.

我只是设法执行以下操作,但是它将浏览器栏中的URL重写为传递的位置,并且没有像以前一样保留该URL:

I just managed to do the following, but it rewrites the url in the browser bar to the passed location and doesn't leave the url as before:

RewriteCond %{HTTP_HOST}  ^testumgebung\.maskesuhren\.de
RewriteRule ^(.*)$ http://www.maskesuhren.de/$1/testumgebung.html [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[^/]+/?$
RewriteRule ^([^/]*)/?$ index.html?nav=$1 [R,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /.*/.*
RewriteRule ^([^/]*)/([^/]*)$ index.html?nav=$1&subnav=$2 [R,L]

推荐答案

您想摆脱最后2条规则中的R:

You want to get rid of the R in the last 2 rules:

RewriteCond %{HTTP_HOST}  ^testumgebung\.maskesuhren\.de
RewriteRule ^(.*)$ http://www.maskesuhren.de/$1/testumgebung.html [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[^/]+/?$
RewriteRule ^([^/]*)/?$ index.html?nav=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /.*/.*
RewriteRule ^([^/]*)/([^/]*)$ index.html?nav=$1&subnav=$2 [L]

方括号中的R告诉mod_rewrite重定向浏览器,这将更改浏览器位置栏中的URL.

The R in the square brackets tell mod_rewrite to redirect the browser, which changes the URL in the browser's location bar. .

这篇关于使用htaccess将目录传递给GET参数而无需重写url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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