Domanda

Recently my hosting provider has been updating their apache systems to 2.4.4. In Doing so it has caused my expression engine site to break because i now need to force query strings to get the site running.

From what i understand your can easily fix this issue by just updating a line in my .htaccess rule to ...

RewriteRule ^(.*)$ /index.php?/$1 [L]

Unfortunately the fix for this was not as simple as this.

My website uses a custom expression engine plugin to detect which region of the world they are in using the IP to Nation Module. What basically happens is that if you are from the United states you see the site with US content & if you are from anywhere else it appends "international" to the first part of the URI which will display the international content based on the first part of our URI

for example

http://www.example.com/segment_1/segment_2/segment_2 = US SITE

http://www.example.com/international/segment_1/segment_2/segment_2 = INTERNATIONAL SITE 

When i try to add that Query string to the rewriteRule for index.php it breaks the international site and i'm not sure why.

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule /international/(.*)$ /index.php/$1 [L]

Adding the "?" to RewriteRule ^(.*)$ /index.php?/$1 [L] fixes the US site but breaks the international site saying it can't find the international page.

Adding the "?" to RewriteRule /international/(.*)$ /index.php?/$1 [L] fixes the International site but then the US site will not work because it needs the query string.

And adding it to them both will not work either.

I'm obviously missing something within .htaccess to overcome this issue but i can't seem to generate the correct syntax.

Any ideas?

È stato utile?

Soluzione

I'm going to take a wild guess here, so could be completely useless...

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule /international/(.*)$ /index.php/$1 [L]

The problem looks like you rewrite the URL adding in the index.php?, then add it in again for the international - hence when you add "?" it to both, it kills the rewrite.

So for the first rewrite you need to exclude international, and for the second ensure it's only effecting international.

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(international)
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} (international)
RewriteRule /international/(.*)$ /index.php?/$1 [L]

You may need to repeat the 3 initial conditions for the second part.

UPDATE

This got it working in the end (Thanks for pointing me in the right direction - Luke)

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(international)
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (international)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule /international/(.*)$ /index.php?/$1 [L]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top