Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite help needed

         

nickkkkky

5:08 am on Dec 12, 2009 (gmt 0)

10+ Year Member



Hi, i need help with the following rewrite

i have 2 domains pointing to the same content, i want 1 domain to be the main domain showing the homepage and couple exception folders, all other contents goes to the other domain.

rewriteEngine on
rewriteCond %{REQUEST_URI} !^/(folder1¦folder2)/
RewriteRule ^/?([^.]*)$ http://example2.com$1 [L]

the above rewrite only works for the folders, how can i add an extra rewriteCond to make the homepage stay at http://example1.com?

[edited by: jdMorgan at 1:51 pm (utc) on Dec. 12, 2009]
[edit reason] De-linked [/edit]

jdMorgan

1:50 pm on Dec 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm gessing you want to exclude "/" (domain root) from being redirected. If so, you can just tweak your existing RewriteCond pattern:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(folder1/¦folder[b]2/¦$[/b])
RewriteRule ^/?([^.]*)$ http://example2.co[b]m/$[/b]1 [R[b]=301[/b],L]

Be sure that links on both domains point to the proper domain for each page and page-included object; You *do not* want to be invoking redirects when browsers or robots follow links on your own site.

That is, this redirect code should be used only to speed up search engine indexing of your new URL-map, and to recover traffic and/or pagerank from bookmarks and links which have not and likely will not be updated. If you're using it for something else, there's probably a better solution available

Also be sure to replace the broken pipe "¦" characters in the patterns above with solid pipes before use; Posting on this forum modifies the pipe characters. Completely-flush (delete) your browser cache before testing any new server-side code.

Jim

nickkkkky

5:30 am on Dec 16, 2009 (gmt 0)

10+ Year Member



hi thanks for the help.. my english is not that great, having hard time understand what you wrote..
my website is a wordpress blog, what i am trying to do is to redirect all old posts and future new posts to a new domain, and only the posts nothing else not even pages. is this the best way to do it?

or is there a way to modify the default wordpress rewrite to achieve the same solution?

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

# END WordPress