使用.htaccess将http://example.com/any/path重写为http://example.com/any

时间:2013-02-21 09:59:47

标签: .htaccess

我想在非现有文件的情况下重写URI - 这应该是我的观点 - 就像这样:

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

我已经使用此规则删除了斜杠:

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

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

1 个答案:

答案 0 :(得分: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]