1

.htaccessを使用してGoogleスタイルのSEOルールを作成していますが、最後の部分で問題が発生しています。

ブラウザにgoogle.com/nexusと入力すると、www.google.com /nexus/にリダイレクトされます。

wwwと末尾のスラッシュが追加されます。

.htaccessでこれを達成するにはどうすればよいですか?

#Start rewrite engine
RewriteEngine on
RewriteBase /

# Enforce www
# If you have subdomains, you can add them to 
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|dev|d10|m)\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Hide the private directory by redirecting the request to index.php
RewriteRule ^(private|\.git) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

速度/スケーラビリティを改善する場所があれば、それが最もありがたいです。

私の最終的な解決策:

RewriteEngine on
RewriteBase /        

# Enforce www
# If you have subdomains, you can add them to 
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|dev|d10|m)\.    
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Add Trailing Slash
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]


# Hide the private directory by redirecting the request to index.php
RewriteRule ^(private|\.git) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
4

2 に答える 2

1
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ http://example.com/$1/ [R=301,L]

example.com を自分のドメインに置き換えます。

于 2012-06-01T19:48:06.230 に答える
0
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L] 

主要な www http://www.cyberciti.biz/faq/apache-redirect-domaincom-to-wwwdomaincom/

于 2012-06-01T19:48:15.787 に答える