我想更改网址:
http://subdomain.domain.com/page/
至http://subdomain.domain.com/?page=pagename
还有:
http://domain.com/page/
至http://domain.com/?page=pagename
虽然没有取得多大成功。
到目前为止,这是我的htaccess文件[已更新]
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Remove 'www'
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Add slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://resolutiongaming.com/$1/ [L,R=301]
# Subdomain redirect
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1
我使用的RewriteRule ^([a-zA-Z]+)/$ ?page=$1
似乎适用于域网址但不适用于子网域。任何帮助将不胜感激。
答案 0 :(得分:0)
最近实际上不得不做这样的事情。请尝试使用子域重定向块:
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$2 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$2 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$2 [R=301,L]
或者也许这个;请注意从 $ 2 到 $ 1 :
的更改 RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
编辑:或者也许试试这个。请注意,您需要捕获URL的两个部分,以便在解释时重写。括号(
和)
中的每个项对应于重写中的字符串。试试这个。正如您在评论中提到的那样使用更好的正则表达式RewriteRule
:
RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/$2 [R=301,L]
或许这个:
RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/page=$2 [R=301,L]
答案 1 :(得分:0)
所以这真的很容易解决。我基本上将.htaccess文件放在每个子域目录中,如下所示:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1
希望这有助于某人。 :d