doufan9395
2014-06-02 21:07
浏览 43
已采纳

htaccess重写和重定向URL

i'm looking for a htaccess rule that can do this:

Original URL: ?til=main Replace to: /main

and if this is the scenario:

Original URL: /index.php?til=main or ?til=main Redirect to: /main

Till now i only have this code:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?til=$1 [L,QSA]

It loads /main but behind it loads /index.php?til=main

图片转代码服务由CSDN问答提供 功能建议

我正在寻找可以执行此操作的htaccess规则:

原始网址 ?til = main 替换为: / main

如果是这种情况:

原始网址: /index.php?til=main ?til = main 重定向到: / main

直到现在我只有这段代码:

  RewriteCond%{REQUEST_FILENAME}!-f 
RewriteCond%{REQUEST_FILENAME}!-d 
RewriteRule ^(。*)$ index.php?til = $ 1 [L,QSA] \  n   
 
 

它加载 / main 但在它后面加载 /index.php?til=main

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanche4578 2014-06-02 22:00
    已采纳

    This should work:

    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^(GET|POST)\ /\?til=(.*)\ HTTP [OR]
    RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?til=(.*)\ HTTP
    RewriteRule ^ /%2? [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?til=$1 [L]
    

    It should redirect index.php?til=main and ?til=main to /main

    点赞 打赏 评论
  • douxian1770 2014-06-02 21:35

    Try:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \ /+(?:index\.php|)\?til=([^&\ ]+)
    RewriteRule ^ /%1? [L,R]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ /index.php?til=$1 [L,QSA]
    
    点赞 打赏 评论

相关推荐 更多相似问题