質問

I need to permanently redirect part of a website to a different domain and URL structure.

Everything that matches: example.com/year/month/day/page-name/ and www.example.com/year/month/day/page-name/

Needs to redirect to: www.sample.com/sub/sub2/year/month/page-name/

For example: example.com/2013/11/09/a-great-page/

should permanently point to: www.sample.com/sub/sub2/2013/11/a-great-page/

But I don't want to redirect any other pages on the site: example.com/a-random-page Shouldn't redirect anywhere.

My htaccess chops and regex skills are a little rusty, so any help would be greatly appreciated!

役に立ちましたか?

解決

Enable mod_rewrite and .htaccess through httpd.conf (if not already enabled) and then put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{SERVER_PORT}s ^(443(s)|\d+s)$
RewriteRule ^([0-9]{4}/[0-9]{2}/[0-9]{2}/[^/]+/?)$ http%2://sample.com/sub/sub2/$1 [L,QSA,R=301]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top