.htaccess method for directing a user?

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Michael Harrison
Regular
Posts: 51
Joined: Sat Jan 28, 2006 12:50 pm

.htaccess method for directing a user?

Post by Michael Harrison »

I thought since I'm trying to do the following in a directory containing s9y I'd ask this question here.

I have a domain "laserscoop" that goes to dragonseye.com that I'd like redirected to a particular category in my blog if the user didn't ask for a particular topic or category. IE, if they only put in http://www.laserscoop.com and not http://www.laserscoop.com/archive/blahdeblah or some such I'd like to send them to a particular category.

At the moment I've got code to direct users to the main blog page all the time but am not quite sure how to set it up so they go to a particular category if they don't specify a page in their browser. Can anyone help?

Here's what I've got in my root .htaccess. (I've left my s9y .htaccess alone)

#
# redirect any requests for http://www.laserscoop.com/* to /blog
#
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.laserscoop\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/ [NC]
RewriteRule ^(.*)$ /blog/$1 [NC,L]

My "normal" blog is at http://www.dragonseye.com/blog
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

So really, you only want to redirect them when they type http://www.laserscoop.com or http://www.laserscoop.com/ -- anything else should work as it does now?

Any invalid request should redirect to the blog front page; if you'd like to make that category the front page, there's a plugin to do it.

If you want to keep the normal front page, I'd add an index.html in my main directory, and have it do the redirection with both HTML and JavaScript.

If you really want to do it in .htaccess, try this:

Code: Select all

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.laserscoop\.com$ [NC]
RewriteRule ^/$ http://www.dragonseye.com/blog/categories/1-Category
Judebert
---
Website | Wishlist | PayPal
Michael Harrison
Regular
Posts: 51
Joined: Sat Jan 28, 2006 12:50 pm

Post by Michael Harrison »

I officially give up for the time being. I have wasted way too much time (especially thanks to Firefox's tendency to cache changes to .htaccess somehow)

I found that the code you sent wouldn't work but the following does...

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.laserscoop\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/ [NC]
RewriteRule ^$ http://www.google.com [L]

but the following just takes me to my main page (without any errors in my server log)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.laserscoop\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/ [NC]
RewriteRule ^$ /blog/index.php?categories/9-NewsGeneral [L]

this goes to the main page too

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.laserscoop\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/ [NC]
RewriteRule ^$ http://www.dragonseye.com/blog/index.ph ... ewsGeneral [L]

even though I can type that address in my browser and get to the right category.

Thanks for your help though, at the moment I'd like to throttle apache.
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

I think you need to include the QSA flag on anything that includes the question mark, as in

Code: Select all

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.laserscoop\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/ [NC]
RewriteRule ^$ http://www.dragonseye.com/blog/index.php?categories/9-NewsGeneral [L,QSA] 
Judebert
---
Website | Wishlist | PayPal
Michael Harrison
Regular
Posts: 51
Joined: Sat Jan 28, 2006 12:50 pm

Post by Michael Harrison »

Thanks for your help. That last tip got me over the hump in that it sent me off looking for helpful flags. It turns out that part of the key was to put the [R] flag in so that URL prefixes wouldn't be stripped. What I finally settled on was the following

#
# redirect any requests for http://www.laserscoop.com/* to the news category in the blog
#
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.laserscoop\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/ [NC]
RewriteRule ^$ http://www.laserscoop.com/blog/index.ph ... ewsGeneral [L,NC,QSA,R]
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Congratulations! Glad we could be of service.
Judebert
---
Website | Wishlist | PayPal
Post Reply