1

I need to redirect this:

http://domain.com/anotherdomain.com

to

http://domain.com/subfolder/?website=anotherdomain.com

The URL anotherdomain.com will be dynamic. It should only detect domains entered after the root domain and not other subfolders. Ex:

SHOULD REDIRECT

domain.com/anotherdomain.com

SHOULDN'T REDIRECT

domain.com/internet-marketing-services/search-engine-optimization-services/

What I've tried:

<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(/|index.php)?$ /link-building-services/?website=%1 [R=301,L]
</IfModule>
4

1 回答 1

1

它不起作用的原因是因为%1匹配组被捕获RewriteCond而您没有在RewriteCond. 捕获的变量RewriteRule$1, $2, $3etc表示。

用这个替换你的代码:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^.]+\..+)$ /link-building-services/?website=$1 [R=301,L]
于 2013-08-01T15:45:27.663 回答