WordPress.org

Ready to get started?Download WordPress

Forums

htaccess (12 posts)

  1. mocco
    Member
    Posted 2 years ago #

    Hi there,

    i have a question how can i redirect with rewriterule wordpress page/post to external webpage

    Thanks for tips.

  2. equalmark
    Member
    Posted 2 years ago #

  3. ce_bradm
    Member
    Posted 2 years ago #

    Hi mocco. Can you give us a specific example of what you're trying to do? For example, do you want http://domain.com/category/post to redirect to http://otherdomain.com ?

    You may want to try:

    RewriteCond %{HTTP_HOST} ^whhsupport.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.whhsupport.com$
    RewriteRule ^category\/post$ "http\:\/\/otherdomain\.com" [R=301,L]
  4. mocco
    Member
    Posted 2 years ago #

    example

    hxxp://www.bestsponsors.info/sample-page/ to hxxp://www.google.com

    RewriteCond %{HTTP_user_agent} googlebot^$ [NC]
    RewriteRule ^sample-page/$ "http\:\/\/google\.com" [NC,L]

    is that right ?

  5. mocco
    Member
    Posted 2 years ago #

    And equalmark

    I want to do this in htaccess. Without wordpress plugins. but thank you for your help.

  6. ce_bradm
    Member
    Posted 2 years ago #

    You may want to try this:

    RewriteCond %{HTTP_HOST} ^bestsponsors.info$ [OR]
    RewriteCond %{HTTP_HOST} ^www.bestsponsors.info$
    RewriteRule ^sample-page$ "http\:\/\/google\.com" [R=301,L]

  7. mocco
    Member
    Posted 2 years ago #

    not working :/

  8. MickeyRoush
    Member
    Posted 2 years ago #

    Try removing the escapes (escapes are not needed in url):

    RewriteRule ^sample-page$ "http\:\/\/google\.com" [R=301,L]

    to this (all you need is the exact URL that you're directing them to) (there is a difference between external and internal redirects, so I'm not sure what you're exactly trying to do):

    RewriteRule .* http://google.com/ [L]

    So try this:

    RewriteCond %{REQUEST_URI} ^http://www.bestsponsors.info/sample-page/$ [NC]
    RewriteRule .* http://google.com/ [NC,L]

    or

    RewriteCond %{THE_REQUEST} ^http://www.bestsponsors.info/sample-page/$ [NC]
    RewriteRule .* http://google.com/ [NC,L]

    Remove the $ symbol if you don't want to be that specific, for exmaple if you're wanting to including sub-directories, etc that need to be redirected as well.

  9. MickeyRoush
    Member
    Posted 2 years ago #

    oops forgot the HTTP_user_agent. I believe it needs some adjusting as well. The way you have it, it states user agent googlebot blank. The blank be provided by ^$. I would just do it like the following, moving the ^ to the front of googlebot and removing the $ as you may not want to be that specific.

    Try these:

    RewriteCond %{HTTP_user_agent} ^googlebot [NC]
    RewriteCond %{REQUEST_URI} ^http://www.bestsponsors.info/sample-page/$ [NC]
    RewriteRule .* http://google.com/ [NC,L]

    or

    RewriteCond %{HTTP_user_agent} ^googlebot [NC]
    RewriteCond %{THE_REQUEST} ^http://www.bestsponsors.info/sample-page/$ [NC]
    RewriteRule .* http://google.com/ [NC,L]

    What this states is, if the user agent is googlebot (including variants) and they are requesting the specific page (remove the $ if you do not want it to be that specific), then send them to the RewriteRule.

  10. MickeyRoush
    Member
    Posted 2 years ago #

    RewriteCond %{HTTP_user_agent} ^googlebot [NC]
    RewriteCond %{REQUEST_URI} ^http://www.bestsponsors.info/sample-page/$ [NC]
    RewriteRule .* http://google.com/ [NC,L]

    or

    RewriteCond %{HTTP_user_agent} ^googlebot [NC]
    RewriteCond %{THE_REQUEST} ^http://www.bestsponsors.info/sample-page/$ [NC]
    RewriteRule .* http://google.com/ [NC,L]
  11. MickeyRoush
    Member
    Posted 2 years ago #

    If neither of those work, try this (HTTP_HOST may be required):

    RewriteCond %{HTTP_user_agent} ^googlebot [NC]
    RewriteCond %{HTTP_HOST} ^http://www.bestsponsors.info/sample-page/$ [NC]
    RewriteRule .* http://google.com/ [NC,L]
  12. mocco
    Member
    Posted 2 years ago #

    solution that worked for me:

    #RewriteCond %{REQUEST_URI}  ^/sample-page/        [NC]
    #RewriteRule ^.*$ http://www.google.com [R=301,L]

    Thank for help!

Topic Closed

This topic has been closed to new replies.

About this Topic