.htaccess他のサブディレクトリを壊さずにWordpressサブディレクトリを書き換えます
だから私はWordPressをインストールして/wp/
いますが、すべてのWordPressURLを書き直してルートディレクトリに表示したいと思います。私は現在これを機能させています(以下を参照)が、.htaccess
他のサブディレクトリを壊さないように変更したいと思います。
たとえば、にアクセスしたい場合www.example.com/images/image.png
、現在、WordPressの404ページに再ルーティングされます。
これはでさえ可能.htaccess
ですか?
現在のコード:
RewriteEngine on
#Wordpress
# Rewrites all URLS without wp in them
RewriteCond %{REQUEST_URI} !^/wp/
# Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /wp/$1 [L]
更新:シークレットモードと2番目のブラウザでMrWhiteの提案をテストしました。無効。新しい.htaccess
ファイル:
RewriteEngine on
#Wordpress
# Rewrites all URLS without wp in them
RewriteCond %{REQUEST_URI} !^/wp/
# Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /wp/$1 [L]
# Request does not map to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
回答
既存のファイルを除外する条件を追加する必要があります。そうしないと、リクエスト/images/image.png
が自然に書き換えられ/wp/images/image.png
、WordPressで404がトリガーされます(/wp/images/image.png
実際に存在しない場合)。
たとえば、既存のルールに次の条件を追加します。
# Request does not map to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
更新:これは機能していないようです。それでもWordPress404ページに移動します
あなたは入れているRewriteCond
間違った場所にディレクティブを。
RewriteCond
ディレクティブは完全に別個のステートメントではなく、後続のディレクティブに適用される条件ですRewriteRule
。RewriteCond
ディレクティブ自体は何もしません。
RewriteCond
(どこかに)行くためのディレクティブのニーズの前にRewriteRule
ディレクティブ:
RewriteEngine on
#Wordpress
# Rewrites all URLS without wp in them
RewriteCond %{REQUEST_URI} !^/wp/
# Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Request does not map to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /wp/$1 [L]
また、サブディレクトリの「WordPress」.htaccess
ファイル/wp
を参照してください。それは同じようなことをします。
余談ですが、書き換えたくないドメインまたはサブドメインが複数ある場合を除いて、ホスト名チェック(つまりRewriteCond
、HTTP_HOST
サーバー変数をチェックするディレクティブ)を削除できます。