4

リダイレクトしたい

  • www.example.com/*example.com/*

そして同時にリダイレクト

  • example.com/*example.com/forum/*

しかし、私は/wiki/andも持っ/blog/ている/style/ので、リダイレクトしたくありません

  • example.com/style/*example.com/forum/style/*

これは私が現時点で持っているもので、正しく動作していません:

Options +FollowSymLinks
RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/forum/
RewriteRule ^(.*)$ forum/$1 [R=301,L]

明確化: 私の質問は、より簡単な方法で尋ねることができます。

ルート ディレクトリにある場合にのみ、空の REQUEST_URIまたは/、または存在しないファイルを/forum/にリダイレクトしたいと思います。

4

4 に答える 4

2

これを試して:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://example.com/$1 [R=301,QSA,L]

RewriteCond %{REQUEST_URI} !^/(wiki|blog|style|forum)
RewriteRule ^(.*)$ http://www.example.com/forum/$1 [R=301,QSA,L]
于 2009-04-23T15:10:24.107 に答える
1

私はこれらのルールを使用します:

# redirect www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^ http://example.com%{REQUEST_URI} [L,R=301]

# prefix everything but /forum/, /wiki/, /blog/, /style/ with /forum/ and rediret to it
RewriteRule !^(forum|wiki|blog|style)/ /forum%{REQUEST_URI} [L,R=301]

さらに、2 番目のルールをこのルールに置き換えて、すべてのリクエストの最初のパス セグメントの存在をチェックすることもできます。

# check if first segment of requested URI path is either missing
RewriteCond $0 ^$ [OR]
# or cannot be mapped to an existing directory
RewriteCond %{DOCUMENT_ROOT}$0/ !-d
RewriteRule ^[^/]* /forum%{REQUEST_URI} [L,R=301]
于 2009-04-23T15:19:37.753 に答える
0

私はこれがうまくいくはずだと思います。

RewriteEngine on
RewriteRule ^forum/(.*)$ forum/$1 [L]
RewriteRule ^wiki/(.*)$ wiki/$1 [L]
RewriteRule ^blog/(.*)$ blog/$1 [L]
RewriteRule ^style/(.*)$ style/$1 [L]

RewriteRule ^(.*)$ forum/$1 [L]

RewriteCond  %{HTTP_HOST}  ^www.example\.com$
RewriteRule ^(.*)$ http://example.com/$1
于 2009-04-23T15:05:54.897 に答える