简体   繁体   中英

How to write htaccess to redirect my site?

I use SMF to running my forum.

This is old forum URL => hxxp://www.example.com/

But now, I move my forum to "forum" folder => hxxp://www.example.com/forum/

Google and other search engine indexed my site with url: hxxp://www.example.com/index.php?topic=99.0

And when users go to hxxp://www.example.com/index.php?topic=99.0 , It's not found.

Because he must to go to hxxp://www.example.com/forum/index.php?topic=99.0 , right?

So, I want to redirect url from hxxp://www.example.com/index.php?topic=99.0 to hxxp://www.example.com/forum/index.php?topic=99.0

How should I do? I try this but not work.

RewriteEngine On
RewriteBase /
RewriteRule ^index.php?topic=([0-9]+).([0-9]+)$ forum/index.php?topic=$1.$2 [R]

我想您必须在 RewriteRule 中转义点 ( . ) 元字符:

RewriteRule ^index\.php?topic=([0-9]+)\.([0-9]+)$ /forum/index.php?topic=$1.$2 [R]

i hope this will help u

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
RewriteRule ^index.php?topic([=0-9.]+)$  old/index.php?topic=$1 [QSA,L] 

depends on where you put htaccess. If it is in /forum/ then

RewriteCond %{REQUEST_URI} !^\/forum\/
RewriteRule ^index\.php$ http://%{HTTP_HOST}/forum/index.php [R]

AFAIK query string is not affected by RewriteRule regexp. http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM