pocobueno1388 Posted December 7, 2011 Share Posted December 7, 2011 I'm trying rewrite the index URL of my website to always include some extra information in the URL. I want to do this for ONLY the index file. For example, I want to change: www.domain.com ---> www.domain.com?index=true I have it working for if they enter the URL WITHOUT the WWW, but I want it to work no matter what format they put the URL in. Here is the semi-working code RewriteEngine on RewriteCond %{HTTP_HOST} ^domain.com [NC] RewriteRule ^(.*)$ http://www.domain.com?index=true/$1 [L,R=301] I'm just not sure what to change the second line to in order to include ALL formats of the name. Any help is greatly appreciated, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/252708-htaccess-rewrite-help/ Share on other sites More sharing options...
requinix Posted December 7, 2011 Share Posted December 7, 2011 :-\ What you have rewrites everything from domain.com. Everything. Not just the index page. RewriteEngine on RewriteCond %{REQUEST_URI} !^/(index.php)?\?(.+&)*index=true(&|$) RewriteRule ^(index.php)?$ /?index=true [L,QSA,R] And are you sure you want the user seeing that ?index=true? Normally one would not... Quote Link to comment https://forums.phpfreaks.com/topic/252708-htaccess-rewrite-help/#findComment-1295536 Share on other sites More sharing options...
pocobueno1388 Posted December 7, 2011 Author Share Posted December 7, 2011 Thanks requinix, This is giving my site a redirect loop error. I know it's an odd request to have the index page display a pointless variable, but I promise there is method to my madness So I want to keep the code I already have in the .htaccess file in order for my site to always display http://www.domain.com no matter what they type in. So now I just need to figure out how to get the index to always show the URL with the GET variable in it. Any suggestions to the previous code you posted to make it stop going into a redirect loop? Also, this isn't really a redirect...so do you know if this will hurt my SEO if I already have the index page ranking for multiple keywords? Quote Link to comment https://forums.phpfreaks.com/topic/252708-htaccess-rewrite-help/#findComment-1295545 Share on other sites More sharing options...
requinix Posted December 8, 2011 Share Posted December 8, 2011 Oh, you do want to enforce the www subdomain after all... And I don't like what I wrote anyways. RewriteCond %{HTTP_HOST} !^www.example.com$ RewriteRule ^ http://www.example.com%{REQUEST_URI} [L] RewriteCond %{REQUEST_URI} ^/(index.php)?$ RewriteCond %{QUERY_STRING} !(^|&)index=true(&|$) RewriteRule ^ /?index=true [L,QSA,R] Quote Link to comment https://forums.phpfreaks.com/topic/252708-htaccess-rewrite-help/#findComment-1295580 Share on other sites More sharing options...
pocobueno1388 Posted December 8, 2011 Author Share Posted December 8, 2011 Hmmm...that didn't seem to do anything at all, it didn't even force the www Quote Link to comment https://forums.phpfreaks.com/topic/252708-htaccess-rewrite-help/#findComment-1295594 Share on other sites More sharing options...
requinix Posted December 8, 2011 Share Posted December 8, 2011 You did think to keep the RewriteEngine there, yes? Quote Link to comment https://forums.phpfreaks.com/topic/252708-htaccess-rewrite-help/#findComment-1295890 Share on other sites More sharing options...
pocobueno1388 Posted December 8, 2011 Author Share Posted December 8, 2011 You did think to keep the RewriteEngine there, yes? Oh sheesh, well aren't I just a genius. Thank you so much, works great! Quote Link to comment https://forums.phpfreaks.com/topic/252708-htaccess-rewrite-help/#findComment-1295925 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.