Jump to content

Need mod_rewrite help please


TOA

Recommended Posts

I'm trying to set up my htaccess to support a splash page (I know, I know; I have no choice in the matter). What I'm trying to accomplish (in english) is this:

 

"If the request is for the home page, either in the form of www.domain.com or www.domain.com/index.php, rewrite it to the welcome url"

 

Here's what I have so far, which works, but only targets www.domain.com. I can't get it to also target www.domain.com/index.php

Options +FollowSymLinks
RewriteEngine On 

#
# Make sure we use the full url
#

RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]

#
# If target is index
#

RewriteCond %{HTTP_HOST} ^www.domain.com$

#
# And referrer is not our own
#

RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)*domain\.com 

#
# re-write to splash page
#

RewriteRule ^$ http://www.domain.com/misc.php?page=welcome [L,R=301]

I've tried a few things with no luck, the most recent being

RewriteCond %{REQUEST_URI} ^index\.php$

Any help is greatly appreciated.

 

Thanks for reading everyone.

Link to comment
Share on other sites

Adding

#
# map all requests for index.php to the domain.
#

RewriteRule ^index\.php$ http://www.domain.com [R=301]

seems to have done it.

 

Please, if anyone sees a problem, let me know.

Link to comment
Share on other sites

I guess that didn't work, forget I said that!

 

For some people, they get stuck on the splash page with that last rule in place. Not sure why it would work for some users but not others, but that's what is seeming to happen.

 

So I guess I'm back to needing help :)

Link to comment
Share on other sites

Well, turns out that even the original code I posted causes a loop for some people. It seems like it's on IE9 only but I don't get completely consistent results because of the index.php thing (I think).

 

I'm just going to start over I think.

 

Does anyone have any ideas why that code was incorrect? It looked right to me.. :-\

Edited by TOA
Link to comment
Share on other sites

You might want to point out to them that splash pages kill SEO.

 

Thanks, I do appreciate that because it does make my job impossible when his actions cause us to fall in ranking or things like that.

 

I've already lost this argument to the owner though. He wants what he wants. In fact this is the second usability argument I've lost to his narcicism; nobody can tell him anything. So unfortunately I'm stuck. Unless you have some sneaky way of undermining him :pirate:  I need to make this work.

 

Now that I think about it, his other company's website has a splash page too. Guess he just has a thing for them. :facewall:

 

I'm going to go at this again today, got pulled away, so if anyone has any ideas on where I was going wrong with that .htaccess file, I'd still love to hear it.

 

Thanks.

Edited by TOA
Link to comment
Share on other sites

Ummm, well, that's not quite what I was going for; it would only replace the index on the first visit to the site (each time). Obviously I missed the mark :)

 

So if they came to the site the first time, they'd get the  splash page. Once they've been in the site, index would still be the home page. At least that was my plan. Maybe that's not a good plan... :shrug:

 

Does that make any more sense?

 

The thing that was puzzling me was that with the above code, some people would get caught on the splash page but others wouldn't; so it was kinda working, but from what I gather it was my logic..

 

Thanks for the help btw.

Edited by TOA
Link to comment
Share on other sites

Yeah, that makes much more sense. It's also more inline with how splash pages normally work.

 

It's much easier to do the splash page stuff in code. You have your index page check for a cookie that's only set once they've seen the splash page. If it's not set you set it and redirect to that page. When they come back the cookie is set, and it will remain set for however long you want it to.

 

If you have to do it with mod_rewrite you can replicate that exact same logic with RewriteCond/%{HTTP_COOKIE} and RewriteRule/the CO flag. Untested but I think you get the gist.

RewriteCond %{HTTP_COOKIE} !(^|;\s*)nosplash=yes
RewriteRule ^index.php$ /misc.php?page=welcome [CO=nosplash:yes:.domain.com,L,R=307]
Edited by requinix
Link to comment
Share on other sites

I had thought about doing it with cookies but was worried about anyone who has them disabled being looped to death :D

 

Some of our clients are in the manufacturing and education industries which are slow to adopt and generally strict with their policies. I checked what stats we have available inhouse and online and from what I can tell by comparing numbers, most of our users are getting logged by google analytics which would infer javascript enabled which would infer (to me at least) cookies enabled, so I think yours may be the more efficient route. I'm going to try some things out and see if I can make your snippet work for me.

 

Thank you very much for the help.

Link to comment
Share on other sites

If you're concerned about cookies being disabled, and you're right that they'd see an infinite loop, then you will need to be able to vary the URL the splash page redirects to.

 

1. As I posted.

2. Make the splash page check for a cookie. If set then all is good and you let things happen normally.

3. If not then the cookie was rejected. Change the URL to the index page so that you can avoid another redirect; with code you'd check $_GET and with mod_rewrite you could

RewriteCond %{HTTP_COOKIE} !(^|;\s*)nosplash=yes
RewriteCond %{QUERY_STRING} !nosplash 
RewriteRule ^index.php$ /misc.php?page=welcome [CO=nosplash:yes:.domain.com,L,R=307]
(and you would redirect to /index.php?nosplash)

 

Problem is that a] anyone could bypass the splash page and b] if you ever link to the index page you'd have to worry about needing to add that ?nosplash (lest they be sent back to the splash page again).

 

So before you start on that, find out if you need to worry about not supporting cookies. Often Javascript and cookies will be disabled at the same time, but that's certainly not something you could rely upon.

 

If you do need to worry then that's one more nail in the coffin of the splash page...

Link to comment
Share on other sites

I'm going to use that in one more last ditch attempt to sway the un-swayable. Wish me luck. At least I have a good idea of what to do if I can't convince him.

 

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.