0

.htaccess ファイルを介して内部リンクをリダイレクトしようとしていますが、機能していません。以下は、私の .htaccess ファイル '# Redirects' です。

リダイレクト リンクが機能するようにコードを構成するにはどうすればよいでしょうか?

# Use PHP 5.3

AddType application/x-httpd-php53 .php 

# Redirect www to non-www

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# BEGIN WordPress

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

# Redirects

Redirect 301 /oldpage http://domain/newpage

# Start Hotlink Protection

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

# EXPIRES CACHING

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/js "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
4

1 に答える 1

0

リダイレクト ステートメントは mod_alias の一部ですが、残りの書き換えルールはすべて mod_rewrite に属します。これら 2 つのモジュールは、処理パイプラインの異なるポイントで要求を処理するため、それらを同時に使用すると、互いにうまく機能しない場合があります。この場合は mod_rewrite を使用するだけでなく、wordpress のルーティング ルールの前にリダイレクト ルールを配置する必要があります。これは、wordpress が実際にリダイレクトしたいものをルーティングするためです。

そう:

# Use PHP 5.3

AddType application/x-httpd-php53 .php 

# Redirect www to non-www

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

#### INSERT THE REDIRECTS HERE
# Redirects

RewriteRule ^oldpage(.*)$ http://domain/newpage$1 [L,R=301]


# BEGIN WordPress

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

### Remove the redirect from here

# Start Hotlink Protection

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

そして、htaccessファイルの残りの部分

于 2013-07-23T17:38:59.383 に答える