htaccess rewrite url and remove question mark |
[eluser]nabasa[/eluser]
Hi there, I need an htaccess 301 redirect for dynamic urls going from this url: http://www.example.com/index.php/?content/page1 to http://www.example.com/content/page1 My current htaccess rule is: RewriteBase / RewriteCond %{HTTP_HOST} !="" RewriteRule ^index.php(/.*)$ http://%{HTTP_HOST}$1 [R=301] the problem is I get urls like this: http://www.example.com/?content/page1 How can I remove that question mark (?) from the url. Also this is for about 20 different urls in this pattern. I would like the rule to work for all my urls needing to be 301 in this pattern. My problem is google has a bunch of urls with the index.php/? in them, and I need to 301 redirect them to the clean pages... but I keep getting the ? in the url. Can anyone give me a good htaccess rule to make this work for my clean CI urls? Thanks, Sean
[eluser]bretticus[/eluser]
Your subpattern match includes everything after index.php so this makes sense where you do the replacement. Have you tried: Quote:RewriteBase /
[eluser]nabasa[/eluser]
I just tried you code (thank you for the reply) but it's showing the same ? in the output. I checked on other sites we have done with CI and we have same problem, but I have 1 site with these index.php/? urls in Google index...and I have to 301 them to the right pages... On another note, what about making the index.php/? urls 404? That would help... I guess other people may have this problem too.. thx Sean
[eluser]bretticus[/eluser]
If you want to lose your search ranking than proceed with the 404s but probably not a good idea. ![]() My code was off the top of my head and for demonstration more than anything. However, I think it probably failed because ? is a meta character (not sure in Apache.) Try escaping it in your rule: Quote:RewriteBase / I don't think the forward slash needs escaping. Seeing examples with it unescaped.
[eluser]bretticus[/eluser]
On a side note: Google is indexing these links because your HTML displays them accordingly. Make sure that index.php is hidden via application/config/config.php. That way, when you use any URL functions, you will not get links with index.php in them. Otherwise, your HTML in your views is possibly hard-coded in this manner.
[eluser]nabasa[/eluser]
Hi Bretticus. I don't want to 404. I tried adding the escape but just repeated the original url. I appreciate your help. Any type of config mod I could change? Do you think htaccess is the way to go? Thanks again! Sean
[eluser]bretticus[/eluser]
When you say repeated, do you mean no redirect occurred? Or do you mean you are getting a redirect to the same version of http://www.example.com/?content/page1 ? While you're at it. It wouldn't hurt to post your entire rewrite configuration. Also, might be nice to post one or two of the actual links where this issue is happening.
[eluser]nabasa[/eluser]
OK here is my config: Code: RewriteEngine on here is a sample url: http://www.domain.com/index.php/?content...nservation Our Ci config has $config['index_page'] = ""; Thanks for checking it out. Sean
[eluser]bretticus[/eluser]
You should put that last rule (the one we've been working on) first and make sure it stops with the last switch ( [R=301,L] ) Not sure why the rewrite condition in the following rule is necessary either: Quote:RewriteCond %{SERVER_PORT} 80 Since it seems you are just trying to redirect when the IP was submitted in the URL? Actually not sure really still. I just know that the following lines: Quote:RewriteCond %{REQUEST_FILENAME} !-f Should take care of hiding index.php for you. By the way, your example shows your ? mark unescaped still???
[eluser]nabasa[/eluser]
The first one is to make sure they use https for different programs with submitting secure info. You should have a link to my website with the redirect... I still have the ? in the processed url. I even tried manual redirect Code: redirect 301 /?content/maui-ocean-conservation http://www.domain.com/content/maui-ocean-conservation and I get that ? too... It looks like my only option which I don't want to do is to put all these index.php/? urls in no-index in robots.txt and resubmit my sitemap... I'm open to any suggestions.. Apparently if I request them to be removed, unless they are 404 or no-index, google will not remove them. Thanks again! Sean |
Welcome Guest, Not a member yet? Register Sign In |