欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

xampp中apache的根目录301问题

程序员文章站 2022-03-26 21:13:09
...
Apache的新手,安装XAMPP之后,apache的端口改为7088,想装个wordpress,修改了apache的httpd.conf的根目录配置如下:
DocumentRoot "C:/xampp/wordpress"

    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
    Order allow,deny
    Allow from all

访问http://localhost:7088/和http://localhost:7088/index.php,apache的日志返回301。

::1 - - [24/Jan/2016:20:53:33 +0800] "GET / HTTP/1.1" 301 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
::1 - - [24/Jan/2016:20:54:08 +0800] "GET /index.php HTTP/1.1" 301 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"

但是访问http://localhost:7088/index.html和http://localhost:7088/wp-login.php都能返回200。

::1 - - [24/Jan/2016:20:41:07 +0800] "GET /wp-login.php HTTP/1.1" 200 2713 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
::1 - - [24/Jan/2016:20:59:32 +0800] "GET /index.html HTTP/1.1" 200 5 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"

我发现wordpress的siteURL只要修改为和访问地址一致的时候就会出现这个问题,如果用域名访问wordpress根目录,而siteurl是 http://localhost:7088 的时候,可以访问成功,只是wordpress的主页链接还是指向localhost。

回复内容:

Apache的新手,安装XAMPP之后,apache的端口改为7088,想装个wordpress,修改了apache的httpd.conf的根目录配置如下:

DocumentRoot "C:/xampp/wordpress"

    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
    Order allow,deny
    Allow from all

访问http://localhost:7088/和http://localhost:7088/index.php,apache的日志返回301。

::1 - - [24/Jan/2016:20:53:33 +0800] "GET / HTTP/1.1" 301 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
::1 - - [24/Jan/2016:20:54:08 +0800] "GET /index.php HTTP/1.1" 301 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"

但是访问http://localhost:7088/index.html和http://localhost:7088/wp-login.php都能返回200。

::1 - - [24/Jan/2016:20:41:07 +0800] "GET /wp-login.php HTTP/1.1" 200 2713 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
::1 - - [24/Jan/2016:20:59:32 +0800] "GET /index.html HTTP/1.1" 200 5 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"

我发现wordpress的siteURL只要修改为和访问地址一致的时候就会出现这个问题,如果用域名访问wordpress根目录,而siteurl是 http://localhost:7088 的时候,可以访问成功,只是wordpress的主页链接还是指向localhost。

找到解决的方法了,找到wp-content/themes/[主题名]/functions.php

在第一行增加一行

remove_filter('template_redirect', 'redirect_canonical');

你看一下你的httpd.conf的配置文件里DirectoryIndex设置的是怎样的?