【问题标题】:How to make a redirect with .htaccess?如何使用 .htaccess 进行重定向?
【发布时间】:2013-09-26 05:54:38
【问题描述】:

我只想知道 .htaccess 有可能做一些技巧(重定向)

site.org/member/$var > site.org/member/?id=$var 像这样。

重点只是在 $var 之前添加 ?id(字符串常量)。

会是这样的

重写引擎开启

RewriteRule(或 RewriteMatch)... ...

干杯。

【问题讨论】:

    标签: apache .htaccess web


    【解决方案1】:
    RewriteRule ^(.*)/member/(.*)$ $1/member/?id=$2 [L]
    

    htaccess 基础知识:http://perishablepress.com/stupid-htaccess-tricks/

    【讨论】:

      【解决方案2】:

      试试:

      RewriteCond %{QUERY_STRING} !id=
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^members/(.+)$ /member/?id=$1 [L,QSA]
      

      【讨论】:

        【解决方案3】:

        这允许您将整个网站重定向到任何其他域

        Redirect 301 / http://mt-example.com/
        

        这允许您将 index.html 重定向到特定的子文件夹

        Redirect /index.html http://example.com/newdirectory/
        

        将旧文件路径重定向到新文件路径

        Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html
        

        提供特定索引页面(设置默认处理程序)

        DirectoryIndex index.html
        

        详情:https://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F

        或者

        Options +FollowSymlinks
        RewriteEngine on
        rewritecond %{http_host} ^domain.com [nc]
        rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
        

        详情在:http://www.webconfs.com/how-to-redirect-a-webpage.php

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-03-31
          • 1970-01-01
          • 2018-09-05
          • 2011-08-29
          • 2017-04-15
          • 2013-06-24
          • 2015-08-15
          相关资源
          最近更新 更多