Results 1 to 5 of 5
  1. #1

    .htaccess rewrite rule hell

    This is an aggravating issue.

    This is on a cPanel server with Litespeed as the webserver.

    Expected behaviour:

    Navigating to lysharia.com and its linked wiki in the site works as expected.

    Unexpected behaviour:
    Navigating to dragonfox.net, other domains, do not work as expected. Instead, they get redirected to lysharia.com.

    The behaviour seems to have stopped for now, but I know this was happening, as it was affecting the other domains added in my cPanel account.

    Now, while I'm familiar with .htaccess, I'm not familiar enough with it to know that "I want to do this, so I'll write the rules for that."

    I have noticed in my testing though, the following bit of code:

    Code:
    # do the rewrite
    RewriteRule ^wiki/?(.*)$ /w/index.php?title=$1 [L,QSA]
    This specific bit. How would you rewrite it to specify the domain? It seems that if I edit the above to the below:

    Code:
    # do the rewrite
    RewriteRule ^lysharia.com/wiki/?(.*)$ /w/index.php?title=$1 [L,QSA]
    Things do work... for everything but the wiki. It results in a 404. A domain's /admin directory works as expected when written so that it is restricted only to lysharia.com and not allowed to be generally applied.

    The contents of my .htaccess for the main account. This affects all other addon accounts in the same account is below.

    Code:
    RewriteEngine on
    
    # uncomment this rule if you want Apache to redirect from www.mysite.com/ to www.mysite.com/wiki/Main_Page
    # If the request is not for a valid directory
    RewriteCond %{REQUEST_FILENAME} !-d
    # If the request is not for a valid file
    RewriteCond %{REQUEST_FILENAME} !-f
    # If the request is not for a valid link
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^$ /wiki/Main_Page [R]
    
    # do the rewrite
    RewriteRule ^wiki/?(.*)$ /w/index.php?title=$1 [L,QSA]
    
    # PRETTYURLS MOD BEGINS
    # Pretty URLs mod
    # http://code.google.com/p/prettyurls/
    # .htaccess file generated automatically on: December 3, 2013, 14:31
    
    RewriteEngine on
    RewriteBase /./.
    
    # Rules for: profiles
    RewriteRule ^profile/([^/]+)/?$ ./index.php?pretty;action=profile;user=$1 [L,QSA]
    
    # Rules for: actions
    RewriteRule ^(activate|admin|announce|attachapprove|buddy|calendar|clock|collapse)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(coppa|credits|deletemsg|display|dlattach|editpoll|editpoll2|emailuser)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(findmember|forum|portal|groups|help|helpadmin|im|jseditor)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(jsmodify|jsoption|lock|lockvoting|login|login2|logout|markasread)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(mergetopics|mlist|moderate|modifycat|modifykarma|movetopic|movetopic2|notify)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(notifyboard|openidreturn|pm|post|post2|printpage|profile|quotefast)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(quickmod|quickmod2|recent|register|register2|reminder|removepoll|removetopic2)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(reporttm|requestmembers|restoretopic|search|search2|sendtopic|smstats|suggest)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(spellcheck|splittopics|stats|sticky|theme|trackip|about:mozilla|about:unknown)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(unread|unreadreplies|verificationcode|viewprofile|vote|viewquery|viewsmfile|who)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(\.xml|xmlhttp)/?$ ./index.php?pretty;action=$1 [L,QSA]
    
    # Rules for: topics
    RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;board=$1;topic=$2.0 [L,QSA]
    RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ ./index.php?pretty;board=$1;topic=$2.$3 [L,QSA]
    
    # PRETTYURLS MOD ENDS
    ★ Ramon Reyes @ EidolonHost
    ★ Blesta and InterWorx Reseller. See WebHost Licenses for details.
    ★ We have Let's Encrypt Support

  2. #2
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Quote Originally Posted by Keiro View Post
    Code:
    # do the rewrite
    RewriteRule ^wiki/?(.*)$ /w/index.php?title=$1 [L,QSA]
    This specific bit. How would you rewrite it to specify the domain?
    Code:
    # do the rewrite
    RewriteCond %{HTTP_HOST} lysharia\.com 
    RewriteRule ^wiki/?(.*)$ /w/index.php?title=$1 [L,QSA]
    In general you can put as many rewrite conditions as you like before one rewrite rule. The rule fires if all conditions are satisfied (ie. condition1 AND condition2...) unless you specify [OR] at the end of the RewriteCond line.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  3. #3
    Quote Originally Posted by foobic View Post
    Code:
    # do the rewrite
    RewriteCond %{HTTP_HOST} lysharia\.com 
    RewriteRule ^wiki/?(.*)$ /w/index.php?title=$1 [L,QSA]
    In general you can put as many rewrite conditions as you like before one rewrite rule. The rule fires if all conditions are satisfied (ie. condition1 AND condition2...) unless you specify [OR] at the end of the RewriteCond line.
    Hmmmm... it's still affecting one of my domains in that it prevents the domain's /admin area from even working at all. When browsing to that domain, and hitting anything other than that domain's main area, ie domain.com and not domain.com/admin, domain.com/order, etc... it works.

    But as soon as you hit domain.com/admin, domain.com/order, etc etc... it simply redirects straight back to domain.com.

    I even tried putting RewriteCond %{HTTP_HOST} lysharia\.com at the top of the .htaccess rewrite rule to make sure that it would know to restrict it to lysharia.com.

    Output of .htaccess now:

    Code:
    RewriteEngine on
    # Enforce this only for this domain.
    RewriteCond %{HTTP_HOST} lysharia\.com 
    
    # uncomment this rule if you want Apache to redirect from www.mysite.com/ to www.mysite.com/wiki/Main_Page
    # If the request is not for a valid directory
    RewriteCond %{REQUEST_FILENAME} !-d
    # If the request is not for a valid file
    RewriteCond %{REQUEST_FILENAME} !-f
    # If the request is not for a valid link
    RewriteCond %{REQUEST_FILENAME} !-l
    
    # Doubly make sure this works for this domain only.
    RewriteCond %{HTTP_HOST} lysharia\.com 
    RewriteRule ^$ /wiki/Main_Page [R]
    
    # do the rewrite
    RewriteCond %{HTTP_HOST} lysharia\.com 
    RewriteRule ^wiki/?(.*)$ /w/index.php?title=$1 [L,QSA]
    
    # PRETTYURLS MOD BEGINS
    # Pretty URLs mod
    # http://code.google.com/p/prettyurls/
    # .htaccess file generated automatically on: December 3, 2013, 14:31
    
    RewriteEngine on
    RewriteBase /./.
    
    # Rules for: profiles
    RewriteRule ^profile/([^/]+)/?$ ./index.php?pretty;action=profile;user=$1 [L,QSA]
    
    # Rules for: actions
    RewriteRule ^(activate|admin|announce|attachapprove|buddy|calendar|clock|collapse)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(coppa|credits|deletemsg|display|dlattach|editpoll|editpoll2|emailuser)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(findmember|forum|portal|groups|help|helpadmin|im|jseditor)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(jsmodify|jsoption|lock|lockvoting|login|login2|logout|markasread)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(mergetopics|mlist|moderate|modifycat|modifykarma|movetopic|movetopic2|notify)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(notifyboard|openidreturn|pm|post|post2|printpage|profile|quotefast)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(quickmod|quickmod2|recent|register|register2|reminder|removepoll|removetopic2)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(reporttm|requestmembers|restoretopic|search|search2|sendtopic|smstats|suggest)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(spellcheck|splittopics|stats|sticky|theme|trackip|about:mozilla|about:unknown)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(unread|unreadreplies|verificationcode|viewprofile|vote|viewquery|viewsmfile|who)/?$ ./index.php?pretty;action=$1 [L,QSA]
    RewriteRule ^(\.xml|xmlhttp)/?$ ./index.php?pretty;action=$1 [L,QSA]
    
    # Rules for: topics
    RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;board=$1;topic=$2.0 [L,QSA]
    RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ ./index.php?pretty;board=$1;topic=$2.$3 [L,QSA]
    
    # PRETTYURLS MOD ENDS
    I wonder... is the RewriteBase also needing to be accounted for as well?

    Edit: Surprisingly... it seems that telling Pretty-URLs to rewrite rules for the boards have successfully made it so that the other rewrites now work properly and does not affect the other domains.

    Wow... I was not expecting that at all...
    Last edited by Keiro; 12-07-2013 at 12:03 AM.
    ★ Ramon Reyes @ EidolonHost
    ★ Blesta and InterWorx Reseller. See WebHost Licenses for details.
    ★ We have Let's Encrypt Support

  4. #4
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Quote Originally Posted by Keiro View Post
    I even tried putting RewriteCond %{HTTP_HOST} lysharia\.com at the top of the .htaccess rewrite rule to make sure that it would know to restrict it to lysharia.com.
    That's not how it works. Stack up as many rewriteconds as you like before one rewriterule. But after that you start again from scratch - all previous rewriteconds are ignored. So what you're doing with the "Doubly make sure" needs to be done for every rule.

    I'd suggest you simplify it down and add one set of rules at a time.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  5. #5
    Quote Originally Posted by foobic View Post
    That's not how it works. Stack up as many rewriteconds as you like before one rewriterule. But after that you start again from scratch - all previous rewriteconds are ignored. So what you're doing with the "Doubly make sure" needs to be done for every rule.

    I'd suggest you simplify it down and add one set of rules at a time.
    Ah. That makes sense, seeing the change. I'll be working on reducing it down to a simplified set of rules.
    ★ Ramon Reyes @ EidolonHost
    ★ Blesta and InterWorx Reseller. See WebHost Licenses for details.
    ★ We have Let's Encrypt Support

Similar Threads

  1. Need help about Rewrite Rule (.htaccess)
    By Flor1anHoxha in forum Programming Discussion
    Replies: 6
    Last Post: 08-03-2013, 11:27 PM
  2. .htaccess rewrite rule
    By rockhost in forum Programming Discussion
    Replies: 9
    Last Post: 05-24-2011, 02:38 PM
  3. .htaccess rewrite rule problem - need help
    By l0ck_up in forum Programming Discussion
    Replies: 8
    Last Post: 07-18-2008, 10:52 PM
  4. Help! Convert .htaccess to lighthttpd rewrite rule
    By omega36 in forum Hosting Security and Technology
    Replies: 2
    Last Post: 06-07-2007, 01:04 AM
  5. .htaccess rewrite rule
    By PostiniWholesaler in forum Web Design and Content
    Replies: 1
    Last Post: 11-22-2005, 12:44 PM

Posting Permissions

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