0

我想在不存在文件的情况下重写 URI - 这应该是我的观点 - 像这样:

http://example.com/test/path/examplehttp://example.com/test

我已经用这条规则删除了斜杠:

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

我必须在.htaccess文件中添加什么才能获得所需的功能?

4

1 回答 1

1

如果未使用问题中的规则集,您可以尝试以下操作:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule  ^([^/]+)/.+/?  $1?  [R=301,L]

永久重定向

http://example.com/folder/with/any/path或任何查询

到:

http://example.com/folder

假定所有字符串都是可变的。

对于静默映射,将 [R=301,L] 替换为 [L]

于 2013-02-21T10:49:38.617 回答