Jump to content

htaccess redirects behaving strangely


bbb
 Share

Recommended Posts

I'm trying to direct all pages from their www and http versions to their non www https versions but I'm experiencing some really strange redirecting behaviour instead.

  • When I uncomment the http to https lines in the htaccess, I get a too many redirects error on my site
  • I thought that Processwire by default redirected from www to non www?

When I apply the following line after the Processwire directives

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

The redirecting seems to work fine but for some reason many of the pages redirect to the homepage.

I don't know if its a factor but I have jumplinks and multi-language installed and running.

I've removed all custom rules from the htaccess just so that people see the pages they click on from search engines, but I'm hoping this can be resolves quick. Ideas?

Link to comment
Share on other sites

maybe you have some other vhost rules active in your hosting settings? some hosting providers have settings to choose a www or non-www version of the site so if the vhost and your htaccess redirect to the opposite it would be an infinite loop.

  • Like 1
Link to comment
Share on other sites

I placed the following rules at the very top of the htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.thedjcompany\.nl [NC]
RewriteRule ^(.*)$ http://thedjcompany.nl/$1 [L,R=301]

RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

also removing the RewriteEngine On which was lower down in the htaccess and now it all works

Link to comment
Share on other sites

31 minutes ago, bernhard said:

maybe you have some other vhost rules active in your hosting settings? some hosting providers have settings to choose a www or non-www version of the site so if the vhost and your htaccess redirect to the opposite it would be an infinite loop.

But I was using standard ProcessWire htaccess, so it should have all been working at ProcessWire intended

Link to comment
Share on other sites

I should mention that I have ProCache installed but not activated at the moment though it was on at some point to test the site. But since the site needed some thorough development, so save time clearing the cache, I simply cleared it and turned it off. I did notice some extra rules in the htaccess because of this. Could that have been the cause? 

Link to comment
Share on other sites

Just now, Peter Knight said:

I had that installed and it showed that Processwire was redirecting my page first tot a page with a get variable ?it= or something or other and then it would redirect to the homepage.

Link to comment
Share on other sites

1 minute ago, Barry said:

I had that installed and it showed that Processwire was redirecting my page first tot a page with a get variable ?it= or something or other and then it would redirect to the homepage.

Glad you go it sorted
Sounds like a caching issue. Even with ProCache turned off, I generally have to resave a page and clear the cache etc.

Link to comment
Share on other sites

  • 1 month later...

Dunno if the problem I have had is exactly the same, but, FWIW, I have a site with ProCache and regardless of whether I delete and rebuild the cache, if I add a redirect in `.htaccess` to a page with an anchor tag, then the site actually ends up at a page with `?it=` and the redirect only gets as far as the page, the scroll to the anchor is ignored.

For me the fix was to use this syntax:

Redirect 301 /my-short-cut http://example.com/the/long/page/to/go-to/?it=qik/my-short-cut#theAnchorIwant

The rule I *would* have used until now was

Redirect 301 /my-short-cut http://example.com/the/long/page/to/go-to/#theAnchorIwant

but that fails as described.

Now I just amend to insert the `/?it=qik/` followed by the text to the right of `301` i.e. `my-short-cut` followed by a `/` and finally the `#anchor`.

This was a hard error I could NOT get rid of and I just had to accept not being able to do this. SO glad I found a workaround, hope this helps others ?

PS: I don't think this is to do with ProCache, I think it's maybe to do with my hoster(?) - I'm not sure, but this one's been *such* a pain I really don't care, just glad to have got past it :)

Link to comment
Share on other sites

@alan, you might be better off using a mod_rewrite rule than using Redirect, because then you can use the [L] flag to avoid the other rewrite rules affecting the URL.

So instead of...

Redirect 301 /my-short-cut http://example.com/the/long/page/to/go-to/#theAnchorIwant

...try...

RewriteRule ^my-short-cut$ http://example.com/the/long/page/to/go-to/#theAnchorIwant [R=301,NE,L]

...just after...

RewriteEngine On

 

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...