想要将 URL 从 www.domain.com/home 更改为 www.domain.com

Posted

技术标签:

【中文标题】想要将 URL 从 www.domain.com/home 更改为 www.domain.com【英文标题】:Want to Change URL from www.domain.com/home to www.domain.com 【发布时间】:2014-05-07 12:19:46 【问题描述】:

这是我的.htaccess 代码:

AddHandler x-httpd-php5-3 .php 重写引擎开启 RewriteBase / RewriteCond %REQUEST_FILENAME !-f RewriteCond %REQUEST_FILENAME/index.html !-f RewriteCond %REQUEST_FILENAME/index.php !-f 重写规则。索引.php [L] RewriteCond %THE_REQUEST /welcome/[/?\s] [NC] 重写规则 ^ / [R=301,L]

【问题讨论】:

【参考方案1】:

您可以在 root .htaccess 中使用此规则:

AddHandler x-httpd-php5-3 .php  
RewriteEngine On
RewriteBase /

RewriteCond %THE_REQUEST /welcome[/?\s] [NC]    
RewriteRule ^ / [R=301,L]    

RewriteCond %REQUEST_FILENAME !-f  
RewriteCond %REQUEST_FILENAME/index.html !-f  
RewriteCond %REQUEST_FILENAME/index.php !-f  
RewriteRule . index.php [L]

【讨论】:

不走运先生。我试过了。这是我的页面名称,具有规范的 URL。整个页面都使用规范 URL,但在主页上我只想删除 /welcome 什么???你的问题说你想删除/home,现在你说的是/welcome。您尝试的完整 URL 是什么?这个 .htaccess 的位置是什么? 好的,我将在根文件夹中向您发送我的 htaccess 代码 再次阅读我的评论,看看您是否回答了我的两个问题。 是的,先生,我知道您已经回复了 /home,但在放置代码时,我将其更改为 /welcome。您现在可以看到我的问题包含我的 htaccess 代码。

以上是关于想要将 URL 从 www.domain.com/home 更改为 www.domain.com的主要内容,如果未能解决你的问题,请参考以下文章

PHP:如何将斜杠添加到绝对 URL

将 www.domain.com 重定向到 sub.domain.com [重复]

使用 Apache 将 URL 路径视为虚拟主机

如何在 Django 下将 domain.com 重定向到 WWW.domain.com?

服务到 301 重定向从 domain.com 到 www.domain.com

使用 RewriteRules 和 404 进行 301 重定向