htaccess 从 www 重定向到 non-www

htaccess redirect to non-www from www

我在这个标题上看到了重复项,但坦率地说,我是 PHP 的新手,不确定 htaccess 是如何工作的。我从某人那里购买了这个脚本,但我没有从那个开发人员那里得到帮助,这就是为什么我是唯一一个解决这个问题的人。

问题 我的旧脚本是我制作的,它曾经被重定向到 http://socialdealers.in/Deals/ 而新脚本是基于 CakePHP 的脚本,它显示了索引上的所有内容,但我仍然即使从主机中删除这些文件后,仍会看到旧的重定向。

网站 http://socialdealers.in

如果你们不明白我想说的话,我很抱歉,但我们将不胜感激。一些开发人员让我在这里问一个关于 Whosebug 的问题,并说它的 .htaccess 问题。

位置 1.htaccess public_html/socialdealers.in/.htaccess

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule    ^$ app/webroot/    [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule    (.*) app/webroot/ [L]

RewriteCond %{SERVER_PORT} !^445$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

</IfModule>
<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

位置 2.htaccess public_html/socialdealers.in/app/.htaccess

# Use PHP5 as default

#AddHandler application/x-httpd-php54 .php

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/    [L]
</IfModule>

位置 3.htaccess public_html/socialdealers.in/app/webroot/.htaccess

# Use PHP5 as default

#AddHandler application/x-httpd-php54 .php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$  http://%{HTTP_HOST}/ [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

编辑: 问题已在 Whosebug 外解决。

编辑了第 3 个 htaccess 文件并将其更改为

# Use PHP5 as default

#AddHandler application/x-httpd-php54 .php

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

您 post 的两个链接都将我引导至 /Deals/,这是一个登录/注册页面。这不是你的目标吗?

(1) 如果您认为问题出在 .htaccess 文件上,您能否展示您的 .htaccess 文件的内容以帮助我们所有人(包括您)解决您的问题。 .htaccess 文件位于您的网络服务器上,可能位于您网站的根文件夹中。

.htaccess 文件中的简单重定向示例如下所示:

Redirect 301 /OLDFILE.html /NEWFILE.html

另一个在所有页面上使用正则表达式强制非 www 的重定向示例可能如下所示:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^YOURDOMAIN.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.YOURDOMAIN.com [NC]
RewriteRule ^(.*)$ http://YOURDOMAIN.net/ [L,R=301,NC]

(2) 如果您认为问题出在您的 PhP 代码上,那么您是否也可以 post 有关如何设置重定向的更多信息或仅显示一些代码。

已在 Whosebug 外部解决。

编辑了第 3 个 htaccess 文件并将其更改为

# Use PHP5 as default

#AddHandler application/x-httpd-php54 .php

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>