Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 将www重定向到非www works适用于除根URL之外的所有URL_Wordpress_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Wordpress 将www重定向到非www works适用于除根URL之外的所有URL

Wordpress 将www重定向到非www works适用于除根URL之外的所有URL,wordpress,apache,.htaccess,mod-rewrite,Wordpress,Apache,.htaccess,Mod Rewrite,我的ApacheHTAccess文件中有以下代码,用于将wordpress上的所有www URL重定向到非www URL。这适用于除根以外的所有URL 例如,正确重定向到。但是,错误地重定向到(接收404页) 我不明白为什么除了根以外所有的ULR都能工作。任何帮助都将不胜感激 RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.noshon\.it$ [NC] RewriteRule ^(.*)$ http://noshon.it/$1 [R

我的ApacheHTAccess文件中有以下代码,用于将wordpress上的所有www URL重定向到非www URL。这适用于除根以外的所有URL

例如,正确重定向到。但是,错误地重定向到(接收404页)

我不明白为什么除了根以外所有的ULR都能工作。任何帮助都将不胜感激

RewriteEngine On   
RewriteCond %{HTTP_HOST} ^www\.noshon\.it$ [NC]  
RewriteRule ^(.*)$ http://noshon.it/$1 [R=301,L]  
RewriteBase /  
RewriteRule ^index\.php$ - [L]  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule . /index.php [L]  

感谢@WebChemist建议重定向发生在另一个文件中。我在bitnami EC2实例的/opt/bitnami/apps/wordpress/conf/目录中找到了一个名为wordpress.conf的文件。此文件具有以下代码:

# App url moved to root
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
#Alias /wordpress/ "/opt/bitnami/apps/wordpress/htdocs/"
#Alias /wordpress "/opt/bitnami/apps/wordpress/htdocs"

<Directory "/opt/bitnami/apps/wordpress/htdocs">
    Options Indexes MultiViews +FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    RewriteEngine On
    #RewriteBase /wordpress/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
<//Directory>

# Uncomment the following lines to see your application in the root
# of your URL. This is not compatible with more than one application.
RewriteEngine On
RewriteRule ^/$ /wordpress/ [PT]
我将此文件修改为以下内容,重定向现在可以正常工作:

# App url moved to root
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
#Alias /wordpress/ "/opt/bitnami/apps/wordpress/htdocs/"
#Alias /wordpress "/opt/bitnami/apps/wordpress/htdocs"

<Directory "/opt/bitnami/apps/wordpress/htdocs">
    Options Indexes MultiViews +FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    RewriteEngine On
    #RewriteBase /wordpress/
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
<//Directory>

# Uncomment the following lines to see your application in the root
# of your URL. This is not compatible with more than one application.
#RewriteEngine On
#RewriteRule ^/$ /wordpress/ [PT]
#应用程序url已移动到根目录
DocumentRoot“/opt/bitnami/apps/wordpress/htdocs”
#别名/wordpress/“/opt/bitnami/apps/wordpress/htdocs/”
#别名/wordpress”/opt/bitnami/apps/wordpress/htdocs“
选项索引多视图+FollowSymLinks
允许超越所有
命令允许,拒绝
通融
重新启动发动机
#重写BASE/wordpress/
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则。index.php[L]
#取消注释以下行以在根目录中查看应用程序
#你的URL地址。这与多个应用程序不兼容。
#重新启动发动机
#重写规则^/$/wordpress/[PT]

htaccess文件在哪里?我认为重定向在php中的某个地方,或者在apache congig中的其他地方,因为返回301的唯一规则是RewriteRule^(.*)$[R=301,L],但这不会将“wordpress”添加到URL中。为什么要双重转义点字符?使用单反斜杠,否则双反斜杠会转义到文字反斜杠字符BTW cool site,必须尝试以下方法:)@JonLin我正在使用Bitnami图像在EC2上托管。文件夹结构为/opt/bitnami/apps/wordpress/htdocs,其中htdocs文件夹包含wordpress核心文件和主题。.htaccess文件位于htdocs文件夹中。我敢打赌这是由Wordpress本身引起的,您现在已经绕过了这种行为。看看你的wordpress设置和你在那里定义的url
# App url moved to root
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
#Alias /wordpress/ "/opt/bitnami/apps/wordpress/htdocs/"
#Alias /wordpress "/opt/bitnami/apps/wordpress/htdocs"

<Directory "/opt/bitnami/apps/wordpress/htdocs">
    Options Indexes MultiViews +FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    RewriteEngine On
    #RewriteBase /wordpress/
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
<//Directory>

# Uncomment the following lines to see your application in the root
# of your URL. This is not compatible with more than one application.
#RewriteEngine On
#RewriteRule ^/$ /wordpress/ [PT]