Log In · Register

 

Help Topic Rules and Requirements

For a list of all requirements and guidelines pertaining to posting a new Help topic, please click here.

This Month's Contests | Staff Member of the Month | Hosts Looking for Hostees | Hostees looking for Hosts | BigBookofResources

Submission Guidelines

 
Reply to this topicStart new topic
Help with .htaccess file
mipadi
post May 17 2010, 05:07 PM
Post #1


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



I have a website at www.monkey-robot.com/. It's a blog. All my blog files are stored in a /blog subdirectory. Internally, I rewrite the root URL to /blog, which means that when you go to www.monkey-robot.com/ you get the contents of /blog, but through the magic of Apache you don't see the URL change.

That works. What's annoying is that www.monkey-robot.com/blog also shows the front page of the blog, which means the front page exists at 2 different URLs. This is bad. So I want to redirect www.monkey-robot.com/blog to the root URL.

This is my current .htaccess file for doing so:

CODE
ErrorDocument 403 /404.html
ErrorDocument 404 /404.html

Options -Indexes

#### Rewrite Rules ####

RewriteEngine On

# Rewrite monkey-robot.com to www.monkey-robot.com
RewriteCond %{HTTP_HOST} ^monkey-robot\.com$
RewriteRule ^(.*)$ http://www.monkey-robot.com/$1 [R=301,L]

RewriteRule ^$             /blog/               [L]
RewriteRule ^feeds/blog/?$ /feeds/blog/atom.xml [L]


Right after the RewriteRule ^$ /blog/ [L], I tried adding this:

CODE
RewriteRule ^blog/?$ / [R,L]


But that gave me an error with "infinite redirects", probably because of the line before it (even though I thought it shouldn't). So I did this instead:

CODE
RewriteRule ^blog/?$ http://www.monkey-robot.com/ [R,L]


But then I got the following Apache error: Invalid command '[R,L]', perhaps misspelled or defined by a module not included in the server configuration But I'm pretty sure the syntax is correct.

Any ideas?
 
fixtatik
post May 17 2010, 08:56 PM
Post #2


Senior Member
******

Group: Member
Posts: 1,237
Joined: May 2008
Member No: 648,123



Did you write it as "RewriteRull", or was that just a typo on here?
 
mipadi
post May 17 2010, 08:57 PM
Post #3


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



Typo.
 
fixtatik
post May 17 2010, 09:15 PM
Post #4


Senior Member
******

Group: Member
Posts: 1,237
Joined: May 2008
Member No: 648,123



Apache always gives me a headache. I'd always thought when rewriting a URL, it was based on the user-inputted URL, but I guess it's the current URL being read.

So (going out on a limb), when someone's at /, Apache's reading /blog/, but you have a rule to redirect /blog/ to /. Back and forth.

I'd probably just end up doing a redirect in a server-side language with the same regex. If you're determined to keep it in .htaccess, try http://forum.modrewrite.com. There's not much the guy who runs that doesn't know about Apache.
 
mipadi
post May 17 2010, 09:34 PM
Post #5


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



QUOTE(fixtatik @ May 17 2010, 10:15 PM) *
So (going out on a limb), when someone's at /, Apache's reading /blog/, but you have a rule to redirect /blog/ to /. Back and forth.


I thought so, too, but the first rewrite should only rewrite the URL internally, the L command is supposed to stop URL rewriting. But I think that is the problem, so I must have misinterpreted the docs.

QUOTE(fixtatik @ May 17 2010, 10:15 PM) *
I'd probably just end up doing a redirect in a server-side language with the same regex.


Yeah...unfortunately, I can't -- using static HTML pages.
 
barrykins
post May 19 2010, 01:14 PM
Post #6


Senior Member
***

Group: Member
Posts: 73
Joined: Dec 2009
Member No: 754,485



I probably don't get your question but why don't you just forward & mask the domain?
 
mipadi
post May 19 2010, 01:18 PM
Post #7


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



QUOTE(barrykins @ May 19 2010, 02:14 PM) *
I probably don't get your question but why don't you just forward & mask the domain?

Uh...I'm not sure I understand, could you elaborate?
 
barrykins
post May 19 2010, 01:25 PM
Post #8


Senior Member
***

Group: Member
Posts: 73
Joined: Dec 2009
Member No: 754,485



Well as Im reading, I might be wrong but.. Couldn't you go to where your domain name is registered and forward www.blahblah.com to the hosting server and then mask it to always show the URL you want...
 
mipadi
post May 19 2010, 01:29 PM
Post #9


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



QUOTE(barrykins @ May 19 2010, 02:25 PM) *
Well as Im reading, I might be wrong but.. Couldn't you go to where your domain name is registered and forward www.blahblah.com to the hosting server and then mask it to always show the URL you want...


The issue isn't with DNS settings or anything, I just wanted to rewrite some URLs.

Anyway, I fixed it. I changed

CODE
RewriteRule ^$ /blog/ [L]


to

CODE
RewriteRule ^$ /blog/ [L,NS]


which prevents subrequests from being rewritten. Basically, when Apache processes a rewrite rule, it then checks all the rewrite rules again with the rewritten URL (even if you use the "L"ast command). "NS" prevents this from happening for a rule.
 
barrykins
post May 19 2010, 01:38 PM
Post #10


Senior Member
***

Group: Member
Posts: 73
Joined: Dec 2009
Member No: 754,485



Ohh see yup. I misunderstood the question.
 
randycowell
post Jun 7 2010, 07:38 AM
Post #11


Member
**

Group: Member
Posts: 15
Joined: Jun 2010
Member No: 757,866



In general, you should never use .htaccess files unless you don't have access to the main server configuration file and htaccess files must be uploaded as ASCII mode, not BINARY.
 
mipadi
post Jun 7 2010, 09:59 AM
Post #12


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



QUOTE(randycowell @ Jun 7 2010, 08:38 AM) *
In general, you should never use .htaccess files unless you don't have access to the main server configuration file and htaccess files must be uploaded as ASCII mode, not BINARY.


Shared hosting, so I don't have access to the main config. Also, it's uploaded via rsync so the mode isn't a problem.
 
randycowell
post Jun 9 2010, 06:54 AM
Post #13


Member
**

Group: Member
Posts: 15
Joined: Jun 2010
Member No: 757,866



The .htaccess files should not be used when there is no access to the main server configuration file.
 
Mikeplyts
post Jun 9 2010, 09:35 AM
Post #14


Mel Blanc was allergic to carrots.
*******

Group: Official Designer
Posts: 6,371
Joined: Aug 2008
Member No: 676,291



^ A boatload of people already do even without "access to the main server configuration file" and everything works just fine.

What you should have said is "you shouldn't edit the .htaccess file if you don't know anything worth of shit on Apache." And it seems like Michael knows what he's doing.

Anyhow, shouldn't this be resolved? _unsure.gif
 
mipadi
post Jun 9 2010, 11:11 AM
Post #15


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



QUOTE(randycowell @ Jun 9 2010, 07:54 AM) *
The .htaccess files should not be used when there is no access to the main server configuration file.

Pardon? A .htaccess should be used if you can't access the main server config file, unless I am missing something.


QUOTE(Mikeplyts @ Jun 9 2010, 10:35 AM) *
Anyhow, shouldn't this be resolved? _unsure.gif

Meh. Actually, what I thought (and posted) was the solution didn't work. I have a workaround in place, but if I could find a better solution that'd be great.
 

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members: