こんにちは私はメインドメインとサブドメインを持つウェブサイトを持っています..apacheウェブサーバーとcentOS上で実行されています...私はまた次のようなURL書き換えメカニズムを持っています
http://subdomain.domain.com/buy-a-new-car
すべてのサブドメインリクエストをメインドメインにリダイレクトし、URLを次のように書き換えます。
http://domain.com/buy-a-new-car
私がこれまでに持っている.htaccessコードはこれになります:
http://domain.com/index.php?buy-a-new-car
idは(index.php?)の部分を取り除くのが好きですが、私は.htaccessディレクティブを書くのが初めてで、REGEXによって混乱しています
これが私の現在のコードです:
RewriteEngine on
RewriteBase /
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
どんな助けでも大歓迎です!
最初にリダイレクトを実行し、最後に次の宛先にルーティングする必要がありますindex.php
。
RewriteEngine on
RewriteBase /
Options -Indexes -Multiviews
# redirect subdomains to main domain
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
# redirect direct accesses to index.php
RewriteCond %{THE_REQUEST} \ /index\.php\?/([^&\ ]+)&?([^\ ]*)
RewriteRule ^ /%1?%2 [L,R=301]
# route everything to index.php internally
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加