1

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

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

http://www.example.com/foo/(带 / 可选)传递给脚本 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://testumgebung.example.com传递给http://www.example.com/testumgebung.php 。

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

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]
4

2 回答 2

2

你想摆脱R最后两条规则:

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。.

于 2013-10-22T14:46:38.407 回答
1

我必须改变顺序才能达到我想要的

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

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

RewriteCond %{HTTP_HOST} ^testumgebung\. [NC]
RewriteRule ^$ testumgebung.html [L]

并重写 html 以使外部资源以斜杠开头。

于 2013-10-24T11:11:26.023 回答