Results 1 to 7 of 7

Converting .htaccess 301 redirect to nginx

This is a discussion on Converting .htaccess 301 redirect to nginx within the Troubleshooting forums, part of the vBSEO SEO Plugin category; Previously I had the following in my forum .htacces file (my site is in my forum directory, rather than root): ...

  1. #1
    Member
    Real Name
    Aaron Dev
    Join Date
    Mar 2011
    Posts
    72
    Liked
    2 times

    Question Converting .htaccess 301 redirect to nginx

    Previously I had the following in my forum .htacces file (my site is in my forum directory, rather than root):
    Code:
    RewriteCond %{HTTP_HOST} !^www\.studioleaks\.info
    RewriteRule (.*) http://www.studioleaks.info/forums/$1 [R=301,L]
    The first rule rewrites studioleaks.info to Studio Leaks.

    The second rule redirects all requests to Studio Leaks to Studio Leaks.

    How do I convert these rules to Nginx, and where in my vhost.conf should they be placed?

    It's important I get the redirect working, since my site root (i.e. not my forum root) contains an under construction page I normally want hidden unless the site is own for repairs.

  2. #2
    vBSEO Staff Brian Cummiskey's Avatar
    Real Name
    Brian Cummiskey
    Join Date
    Jul 2009
    Location
    btwn NYC and Boston
    Posts
    12,789
    Liked
    657 times
    Blog Entries
    2
    There is only 1 rule there, not two. Think of it as
    IF (conditoin) xxxxx
    THEN (rule) yyyyy END

    nginx uses paths. You should alias the www to the main or vice versa.

  3. #3
    Member
    Real Name
    Aaron Dev
    Join Date
    Mar 2011
    Posts
    72
    Liked
    2 times
    Brian,

    How would I go about that? Sorry if I'm straying off-topic here. I was going to try asking on the nginx forums, but most of the threads I found were just linking to vbseo.com topics. It seems Nginx users think you guys are the experts on... Nginx.

  4. #4
    vBSEO Staff Brian Cummiskey's Avatar
    Real Name
    Brian Cummiskey
    Join Date
    Jul 2009
    Location
    btwn NYC and Boston
    Posts
    12,789
    Liked
    657 times
    Blog Entries
    2
    Unfortunately, i am not. I don't have any more info for you on this.

  5. #5
    vBSEO.com Webmaster Mert Gökçeimam's Avatar
    Real Name
    Lizard King
    Join Date
    Oct 2005
    Location
    Istanbul, Turkey, Turkey
    Posts
    23,111
    Liked
    622 times
    Blog Entries
    4
    Hello Aaron ,

    I already shared you the required rules within the support ticket you created early this morning.
    Mert Gökçeimam / Crawlability Inc.

    vBSEO 3.6.0 Alpha Önizlemesi - Including Like Tree
    Unveiling the NEW vBSEO Sitemap Generator 3.0 - available NOW for vBSEO Customers!


    Twitter:@Depkac
    Personal Blog : Mert Gökçeimam

  6. #6
    Member
    Real Name
    Aaron Dev
    Join Date
    Mar 2011
    Posts
    72
    Liked
    2 times
    Mert, I tried those rules, I can't get them to work. All I'm looking for is a permanent redirect from Studio Leaks to Studio Leaks. I can even live without the trailing slash for now.

  7. #7
    Junior Member
    Real Name
    Julio
    Join Date
    May 2009
    Posts
    14
    Liked
    0 times
    Hi DevOne, I realize this post is kinda old so maybe you solved it already?
    This would be similar to your Apache way, but it is not recommended to use "IF" statement in nginx at all! (Please read "Why If Is Evil and nginx Pitfalls, it is very good on information....)
    Code:
            ## Redirect to Domain if $host does not match www.domain.com
            if ($host != 'www.domain.com' ) {
              rewrite ^/(.*)$ http://www.domain.com/$1 permanent;
            }
    But anyway here it the way I would do it, to save on resources and avoid the "IF" statement
    Code:
        server {
            ## Redirect to Domain if $host does not match www.domain.com
            listen       80 default_server;
            server_name  _;
            rewrite ^ http://www.domain.com$request_uri permanent;
        }
        server {
            limit_conn   myzone  20;
            listen       80;
            server_name  www.domain.com;
            root   /var/www/html;
            index index.php index.html index.shtml index.htm;
            ........
    Now I am purposefully vague in my example, I did not include the redirect to your forum, but you should be able to easily figure that out

    Regards,
    Per Hansson
    Techspot.com

Similar Threads

  1. nginx in htaccess folder
    By m7shsh in forum General Discussion
    Replies: 12
    Last Post: 11-27-2010, 07:07 PM
  2. nginx How to redirect forum.php to root (/)?
    By vbul in forum Custom Rewrite Rules
    Replies: 2
    Last Post: 09-26-2010, 10:56 PM
  3. Nginx rules don't redirect old showthread.php URLs
    By Inettive in forum General Discussion
    Replies: 4
    Last Post: 01-10-2010, 03:19 AM
  4. vBSEO won't redirect to pretty URLs under nginx
    By Viper007Bond in forum Troubleshooting
    Replies: 1
    Last Post: 06-23-2009, 07:08 AM
  5. Converting .htaccess rewrite rule to vbseo rewrite
    By tscargo in forum Custom Rewrite Rules
    Replies: 1
    Last Post: 04-20-2009, 02:34 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •