我的.htaccess中有以下代码:
RedirectMatch permanent /en/(.*) /$1
或
RewriteRule ^en/?(.*)?/?$ $1 [R=301,L,QSA]
使用和/或RewriteBase /
我要做的是将每个http://example.com/en/somthing
重定向到http://example.com/somthing
(无论是否带有斜杠)
相反,当我访问http://example.com/en/admin
(没有斜杠)时,我被重定向到http://example.com//admin
(带有2个斜杠)
当我访问http://example.com/en/admin/
(带斜杠)时一切正常..
每个其他网址都使用尾部斜杠而不是..
我正在使用symfony2,如果这有帮助,这是我的routing.yml
deo_secure:
resource: "@DeoSecureBundle/Resources/config/routing.yml"
prefix: /admin
welcome:
pattern: /
defaults: { _controller: AcmeDemoBundle:Welcome:index }
_demo:
resource: "@AcmeDemoBundle/Controller/DemoController.php"
type: annotation
prefix: /demo
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
deo_secure的路由文件是:
deo_secure_homepage:
pattern: /
defaults: { _controller: DeoSecureBundle:Admin:index }
答案 0 :(得分:0)
你可以尝试这个
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)/en/(.*)
RewriteRule ^ /%2 [R=301,L]
示例:
http://sepidarcms.ir/en/admin/
重定向到:
答案 1 :(得分:0)
您必须将原始指令更改为:
RedirectMatch permanent ^/en/(.*)$ /$1
或更好地将其替换为:
Redirect permanent /en/ /