Jump to content

.htaccess rewrite help


pocobueno1388
 Share

Recommended Posts

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!

 

 

 

 

Link to comment
Share on other sites

:-\

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...

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.