[英].htaccess-The page isn't redirecting properly
我正在嘗試將index.html重定向到home.html,並通過 .htaccess 從 url 中刪除該home.html 。 但它顯示頁面沒有正確重定向。 這意味着我需要將 mydomain.com/index.html 重定向到 mydomain.com/home.html,並且僅在訪問索引頁面時才需要顯示 mydomain.com/。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Redirect 301 "/index.html" "/home.html"
RewriteCond %{THE_REQUEST} ^GET.*home\.html [NC]
RewriteRule (.*?)home\.html/*(.*) /$1$2 [R=301,NE,L]
</IfModule>
您可以嘗試而不是使用 mod_rewrite 將DirectoryIndex設置為所需的頁面(在您的情況下為 home.html):
DirectoryIndex home.html
所以,如果你打電話給domain.com/
它應該給你domain.com/home.html
的內容
供參考,Apache配置手冊: https : //httpd.apache.org/docs/2.4/mod/mod_dir.html "DirectoryIndex Directive"
引用下面的對話:
也許這可以工作(對不起,我現在無法測試)
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} =/index.html
RewriteRule (.*?)home\.html/*(.*) /$1$2 [R=301,NE,L]
稍微解釋一下:如果請求的主機與 example.com 匹配,並且被調用的 URI 實際上不是真正的文件或文件夾,加上 URI 等於“index.html”,它應該重定向到 home.html。
編輯:由於您不想顯示 home.html,我們可以通過在內部“代理”請求而不是強制外部重定向來逃脫。 嘗試用“P”替換最后一行(RewriteRule)中的“R=301”,所以它說RewriteRule (.*?)home\\.html/*(.*) /$1$2 [P,NE,L]
// 這是工作代碼,我希望它有用..
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 / http://newsite.com/
</IfModule>
或者
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?http://dbdenterprise\.in$
RewriteRule ^(.*)$ http://dbdenterprise.com/$1 [R=301,QSA,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.