0

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

例如,http://www.noshon.it/recipes正确重定向到http://noshon.it/recipes。但是,http: //www.noshon.it 错误地重定向到http://noshon.it/wordpress(它会收到 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]  
4

1 回答 1

0

感谢@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]

重写发生在该文件的最后一行:

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]
于 2012-09-18T14:26:13.057 回答