1

私はワードプレスのに加えて書き換えルールを書き込もうとしています:

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

すべてをメインページにリダイレクトしたくありません。リダイレクトする必要のあるサブディレクトリが複数あります: http: //www.example.com/sub1http://www.example.com/sub2。私はこれを行っているので、コンテンツをAjax経由でロードできます。

これは単純に

RewriteRule ^/(sub1|sub2)/(.*)$ http://www.example.com/$1/ [L]

ここのブロックに配置したもの:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(sub1|sub2)/(.*)$ http://www.example.com/$1/ [L]
RewriteRule . /index.php [L]
</IfModule>

おそらくワードプレスでは、wp_rewrite_ruleを使用する必要がありますか?.htaccessファイルをいじって、ルールを機能させてから、関数に移動できると思いました。

どんな助けでもいただければ幸いです。

ありがとう。

更新:.htaccesファイルをwordpressのデフォルトに戻そうとしました...そしてこのコードを私の子テーマのfunctions.phpファイルに追加します:

function AJAX_rewrite_rule() {
add_rewrite_rule(
    '^/(sub1|sub2)/(.*)$',
    'http://www.example.com/$1',
    'top' );
};
add_action( 'init', 'AJAX_rewrite_rule' );

すべての読み込みが遅くなるようですが、見つからないすべてのファイルは、サブディレクトリではなくメインページにリダイレクトされます。

UPDATE#2 add_rewrite_ruleは、wordpressによってすでに配置されている構造にルールを追加するだけなので、私は間違った方向に進んでいたと思います。これはすべて、URLを解釈し、それらをインデックスによって実行されるDBクエリの変数に変更することで機能します。

$wp_rewrite->non_wp_rulesを使用する必要があると確信しています。誰かがもっとアイデアを持っているなら、私に知らせてください。

4

1 に答える 1

0

これを試してみてください。そこに悪い行があるようです:

<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteBase /
# RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f #Means DONT redirect if file exists.
RewriteCond %{REQUEST_FILENAME} !-d #Means DONT redirect if directory exists.
RewriteCond %{REQUEST_URI} !^/sub1/
RewriteCond %{REQUEST_URI} !^/sub2/
# RewriteRule ^/(sub1|sub2)/(.*)$ http://www.example.com/$1/ [L]
RewriteRule . /index.php [L]
</IfModule>

「RewriteRule」を追加するたびに、すべての「RewriteCond」がそのルールに適用され、白紙の状態から開始します。

RewriteCond A
RewriteCond B
RewriteCond C
RewriteRule Whatever [L] #This applies A, B, and C
RewriteRule Another [L] #This applies no rules

おそらくそれが役立つでしょう。

また、それが機能しない場合は、「RewriteEngine On」の直後に「RewriteRule ^/(sub1|sub2)/(.*)$ http://www.example.com/ $1/ [L]」を追加してみてください。 …</p>

于 2012-11-15T16:10:47.427 に答える