【问题标题】:Simple htaccess redirection简单的 htaccess 重定向
【发布时间】:2013-06-21 11:25:39
【问题描述】:

我想创建一个这样的重定向:

   http://www.myserver.com/recipe/xxxxx.html?v1=blabla&fb_action_ids=bla&v3=blablabla

http://www.myserver.com/recipe/xxxx.html

注意:url中的xxxx因页面而异。

htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteRule ^home.htm http://www.xxxxxxxxxx.co.uk/ [R=301,NC,L]
RewriteRule ^breads.htm http://www.xxxxxxxxxx.co.uk/whatwemake/ [R=301,NC,L]
RewriteRule ^cakes.htm http://www.xxxxxxxxxx.co.uk/patisserie/ [R=301,NC,L]
RewriteRule ^farmers_market.htm http://www.xxxxxxxxxx.co.uk/wheretobuy/ [R=301,NC,L]
RewriteRule ^about_us.htm http://www.xxxxxxxxxx.co.uk/ourstory/ [R=301,NC,L]
RewriteRule ^contacts.htm http://www.xxxxxxxxxx.co.uk/contact/ [R=301,NC,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(recipe/[^.]+\.html)\?fb_action_ids=[^\s]+ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(news/[^.]+\.html)\?fb_action_ids=[^\s]+ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(event/[^.]+\.html)\?fb_action_ids=[^\s]+ [NC]
RewriteRule ^ /%1? [R=301,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

SetEnv APPLICATION_ENV production 

【问题讨论】:

    标签: php .htaccess redirect


    【解决方案1】:

    通过httpd.conf启用mod_rewrite和.htaccess,然后把这段代码放到你.htaccessDOCUMENT_ROOT目录下:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+((?:news|event|recipe)/[^.]+\.html)\?fb_action_ids=[^\s]+ [NC]
    RewriteRule ^ /%1? [R=302,L]
    

    一旦您确认它工作正常,请将R=302 替换为R=301。在测试你的 mod_rewrite 规则时避免使用R=301(永久重定向)。

    【讨论】:

    • 这是在做什么[A-Z]{3,}\s/+
    • +1 为您提供帮助,但是,我仍然没有重定向。让我上传我的 htacces
    • @DevZer0: [A-Z]{3,}\s/+ 匹配 GET / OR GET ///
    • @Romain: .htaccess 看起来不错,您尝试使用哪个 URL 进行测试?
    • @Romain:查看我上面关于如何处理 URI 中的 3 个不同路径的答案。
    【解决方案2】:

    这个东西是通过GET方法[?v1=blabla&v2=bla&v3=blablabla]然后使用POST

    【讨论】:

    • 我不想获取任何变量,我只想重定向用户。
    • 这是链接到我的网站的外部链接。有时,人们会在链接中添加变量,而我会显示错误页面。
    • 我想在不获取任何信息的情况下将它们重定向到我的页面
    【解决方案3】:

    你需要一个简单的重写规则

     RewriteRule ^(.*).html(.*) $1.html
    

    【讨论】:

    • 试过了,但重定向没有完成,这里是一个链接示例:xxxxxxxxxx.co.uk/recipe/…+1 寻求帮助
    • AllowOverride All 需要在有 .htaccess 文件的目录或其父目录上设置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-03
    • 1970-01-01
    • 2016-01-28
    • 2011-07-14
    • 2012-05-31
    相关资源
    最近更新 更多