0

htaccessファイルに書き換えルールを追加しようとしていますが、パーマリンク構造を回避できないようです。これが私が試していることです:

Options +FollowSymLinks

# BEGIN MyRules

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^properties/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ ?property=$1&page=$2
RewriteRule ^properties/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ ?property=$1&page=$2
RewriteRule ^agents/(.*)$ ?agent=$1
RewriteRule ^agents/(.*)/$ ?agent=$1
</IfModule>

# END MyRules

# BEGIN WordPress

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

# END WordPress

WordPressは「プロパティ」と「エージェント」をカテゴリとしてレンダリングし続けますが、これらのカテゴリが存在しないため、404エラーが発生します。これらは実際にはページであり、URLを書き換えるためにそれらのページに渡されるパラメーターを取得したいと思います。

ご協力いただきありがとうございます!

4

2 に答える 2

0

ルールを修正し、コメントを追加しました

ブロック全体を繰り返さないでください。<IfModule mod_rewrite.c>別のブロックを追加すると、Apache は最初の " ブロックを忘れてしまう可能性があります (確認していません)。

正規表現は確認していませんが、構文的には問題ないようです

Options +FollowSymLinks

<IfModule mod_rewrite.c>
    # enable the rewrite engine
    RewriteEngine On
    # "/" is the base path to work on
    RewriteBase /

    # dont rewrite calls on index.php
    RewriteRule ^index\.php$ - [L]

    # rewrite the url to index.php and pass query values
    # [L] indicates, that apache does not need to care 
    # about the following rewrites when this matches
    RewriteRule ^properties/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$  /index.php?property=$1&page=$2 [L]
    RewriteRule ^agents/(.*)/?$ /index.php?agent=$1

    # If the request does not point to a existing file ( image.jpg )
    RewriteCond %{REQUEST_FILENAME} !-f
    # If the request does not point to a existing directory ( /, default index.php )
    RewriteCond %{REQUEST_FILENAME} !-d
    # in this cases you would usually say "404 not found" but no, 
    # please direct all those to the index.php which will care of the rest
    RewriteRule . /index.php [L]
</IfModule>
于 2012-11-17T13:08:24.273 に答える
0

書き換えようとしている構造は、使用しているカスタム パーマリンク構造に似ているため、WordPress は既に「名前」や「カテゴリ」などの他のパラメーターをインデックスに渡しているようです。

これらのパラメーターを次のように削除できました。

RewriteRule ^properties/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$  /index.php?property=$1&page=$2&cateogry=&name= [L]

上記のミシェルのアドバイスは間違っていませんが、これは特に私の問題を修正しました.

于 2012-12-09T20:49:20.233 に答える