TOA Posted June 10, 2013 Share Posted June 10, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/279005-need-mod_rewrite-help-please/ Share on other sites More sharing options...
TOA Posted June 10, 2013 Author Share Posted June 10, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/279005-need-mod_rewrite-help-please/#findComment-1435200 Share on other sites More sharing options...
TOA Posted June 10, 2013 Author Share Posted June 10, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/279005-need-mod_rewrite-help-please/#findComment-1435201 Share on other sites More sharing options...
TOA Posted June 11, 2013 Author Share Posted June 11, 2013 (edited) 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 June 11, 2013 by TOA Quote Link to comment https://forums.phpfreaks.com/topic/279005-need-mod_rewrite-help-please/#findComment-1435327 Share on other sites More sharing options...
requinix Posted June 11, 2013 Share Posted June 11, 2013 I'm trying to set up my htaccess to support a splash page (I know, I know; I have no choice in the matter).You might want to point out to them that splash pages kill SEO. Quote Link to comment https://forums.phpfreaks.com/topic/279005-need-mod_rewrite-help-please/#findComment-1435404 Share on other sites More sharing options...
TOA Posted June 12, 2013 Author Share Posted June 12, 2013 (edited) 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 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. 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 June 12, 2013 by TOA Quote Link to comment https://forums.phpfreaks.com/topic/279005-need-mod_rewrite-help-please/#findComment-1435537 Share on other sites More sharing options...
requinix Posted June 12, 2013 Share Posted June 12, 2013 Just to be clear: the method you're going for makes the splash page essentially the homepage, and that also means /index.php is not accessible (because it always sends you to the splash page). That's how it's supposed to work? Quote Link to comment https://forums.phpfreaks.com/topic/279005-need-mod_rewrite-help-please/#findComment-1435584 Share on other sites More sharing options...
TOA Posted June 13, 2013 Author Share Posted June 13, 2013 (edited) 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... 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 June 13, 2013 by TOA Quote Link to comment https://forums.phpfreaks.com/topic/279005-need-mod_rewrite-help-please/#findComment-1435655 Share on other sites More sharing options...
requinix Posted June 13, 2013 Share Posted June 13, 2013 (edited) 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 June 13, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/279005-need-mod_rewrite-help-please/#findComment-1435660 Share on other sites More sharing options...
TOA Posted June 13, 2013 Author Share Posted June 13, 2013 I had thought about doing it with cookies but was worried about anyone who has them disabled being looped to death 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. Quote Link to comment https://forums.phpfreaks.com/topic/279005-need-mod_rewrite-help-please/#findComment-1435787 Share on other sites More sharing options...
requinix Posted June 13, 2013 Share Posted June 13, 2013 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... Quote Link to comment https://forums.phpfreaks.com/topic/279005-need-mod_rewrite-help-please/#findComment-1435856 Share on other sites More sharing options...
TOA Posted June 14, 2013 Author Share Posted June 14, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/279005-need-mod_rewrite-help-please/#findComment-1435895 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.