代码之家  ›  专栏  ›  技术社区  ›  Dipak

重定向到本地主机仪表板而不是项目根目录

  •  2
  • Dipak  · 技术社区  · 6 年前

    我在本地有个网站- ourallnews . 我想重定向所有关键字- index, index.php, index.html 到站点根目录- localhost/ourallnews/ . 我已经应用了以下规则 .htaccess 但是它被重定向到- localhost/dashboard/ . 如何修复?

    RewriteEngine on
    RewriteBase /ourallnews/
    RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,NC,L]
    
    RewriteCond %{THE_REQUEST} /category(?:\.php)?\?cat=([^\s&]+) [NC]
    RewriteRule ^ %1? [R=301,L]
    
    # internal forward from pretty URL to actual one
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([\w-]+)$ category.php?cat=$1 [L,QSA]
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   anubhava    6 年前

    如果你用的是 RewriteBase 然后在重定向时使用相对链接:

    RewriteEngine on
    RewriteBase /ourallnews/
    
    RewriteRule ^(.*)index\.(?:php|html?)$ $1 [R=301,NC,NE,L]
    
    RewriteCond %{THE_REQUEST} /category(?:\.php)?\?cat=([^\s&]+) [NC]
    RewriteRule ^ %1? [R=301,L]
    
    # internal forward from pretty URL to actual one
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([\w-]+)/?$ category.php?cat=$1 [L,QSA]
    

    确保清除浏览器缓存或使用新浏览器进行测试。