【问题标题】:Redirect one URL to another using htaccess使用 htaccess 将一个 URL 重定向到另一个
【发布时间】:2022-01-13 06:58:51
【问题描述】:

我目前的.htaccess文件代码如下:

### ISPConfig folder protection begin ###
AuthType Basic
AuthName "Members Only"
AuthUserFile /var/www/web113/web/.htpasswd
require valid-user
### ISPConfig folder protection end ###


<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [L]

</IfModule>

我想将网址作为http://xxxxx.xxxxxx.net/local-attraction 重定向到http://xxxxx.xxxxx.net/pages/local-attraction

我试过了

RedirectPermanent http://xxxxx.xxxxxx.net/local-attraction http://xxxxx.xxxxx.net/pages/local-attraction

还有

Redirect 301 /local-attraction http://xxxxx.xxxxx.net/pages/local-attraction

但没有任何效果,它显示的是 404 页面。

【问题讨论】:

    标签: .htaccess redirect http-redirect


    【解决方案1】:

    您应该为此重定向使用mod_rewrite 规则,因为您已经在您的.htaccess 中使用它:

    RewriteEngine On
    
    RewriteRule ^local-attraction/?$ /pages/$0 [L,NC,R=301]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
    

    【讨论】:

    • 是的,先生,感谢您的帮助 :)
    猜你喜欢
    • 2013-08-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-28
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 2017-05-18
    • 1970-01-01
    相关资源
    最近更新 更多