Permalinks Plugin and Rackspace Cloud Sites - .htaccess Preferred Domain and HTTP/HTTPS rules

11 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: June 7, 2016   (RSS)

By Steve99 - May 19, 2016

Hello,

We're experiencing an issue with htaccess rules for the Permalinks Plugin on Rackspace Cloud Sites related to Preferred Domain and HTTP/HTTPS. Have been receiving the "permalinks dispatcher not found notice". Perhaps the htaccess rules need tweaking for this hosting environment?

For example, their posted method of routing all traffic to https is the following:

#Force SSL on entire site on Rackspace Cloud Sites
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://(YOURDOMAIN)/$1 [R,L]

Thanks in advance.

Regards,
Steve

By Damon - May 20, 2016

Hi Steve,

After you generated the .htaccess code for redirecting requests, did you uncomment this code to force https?

### Force HTTPS secure connections - Optional security (uncomment to use)
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

And if so, can you next try replacing the above code with Rackspace method:

RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://(YOURDOMAIN)/$1 [R,L]

If this doesn't work, can you post your complete .htaccess code.

Thanks.

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Steve99 - May 23, 2016

Hi Damon,

Yes, uncommented that portion of the generated code and was receiving permalinks dispatcher error.

Yes, tried replacing that code with the Rackspace Cloud Sites method too. Also received permalinks dispatcher error.

Please note that a load balancer comes into play with Rackspace Cloud Sites.

Here is the htaccess code. Most testing rewrite items are commented out because they don't work - just the main rewrite code at the top works without a problem.

# START: CMS Permalink Code
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^permalinks_dispatcher\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /cmsb/plugins/permalinks/permalinks_dispatcher.php [L]
  
  ### Optional SEO Option: Uncomment the rewrite* lines below to remove www. from all pages so you don't have duplicate urls.
  ### Source: http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www
  
  # DEV NOTE: DEFAULT CMSB HTACCESS DOMAIN PREFERENCE CODE DOES NOT WORK ON RACKSPACE CLOUD SITES PERMALINKS PLUGIN
  #RewriteCond %{HTTPS} off
  #RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  #RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  
  #RewriteCond %{HTTPS} on
  #RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  #RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
  
  # DEV NOTE: MODIFIED CMSB HTACCESS DOMAIN PREFERENCE - DOES NOT WORK ON RACKSPACE CLOUD SITES WITH PERMALINKS PLUGIN
  #RewriteCond %{ENV:HTTPS} !on [NC]
  #RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  #RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  
  #RewriteCond %{ENV:HTTPS} on [NC]
  #RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  #RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

  ### Rackspace Cloud Sites - www domain preference - NOT WORKING WITH PERMALINKS PLUGIN
  #RewriteCond %{HTTP_HOST} ^DOMAIN.com [NC]
  #RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=301,NC]
  ### Rackspace Cloud Sites - non-www domain preference - NOT WORKING WITH PERMALINKS PLUGIN
  #RewriteCond %{HTTP_HOST} ^www.DOMAIN.com [NC]
  #RewriteRule ^(.*)$ http://DOMAIN.com/$1 [R=301,L]

  ### Optional Security: Uncomment the rewrite* lines below to force secure HTTPS:// connections for all pages.
  ### NOTE: Make sure https:// urls work on your server before enabling this.
  ### DEV NOTE: DOES NOT WORK ON RACKSPACE CLOUD SITES WITH PERMALINKS PLUGIN
  #RewriteCond %{HTTPS} off
  #RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
  
  ### example for Rackspace Cloud Sites 
  ### DEV NOTE: DOES NOT WORK WITH PERMALINKS PLUGIN
  #RewriteCond %{ENV:HTTPS} !on [NC]
  #RewriteRule ^(.*)$ https://www.DOMAIN.com/$1 [R,L]
  ### End: Optional Security
  
</IfModule>
# END: CMS Permalink Code

Looking to implement the domain preference rewrites for SEO purposes, and https for security.

Thanks in advance,
Steve

By Dave - May 24, 2016

Hi Steve,

First, make sure you're running the latest (non-beta) CMSB and Permalinks plugin:

Next, try the code generated by the latest Permalinks Code Generator:

# Add this to an .htaccess file in your website root folder
# Your website root folder is usually named: htdocs, httpdocs, www, html, or just / in FTP

# START: CMS Permalink Code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

### Set URL_SCHEME (REQUEST_SCHEME isn't available before Apache < 2.4 and can include hostname)
RewriteCond %{HTTPS} off
RewriteRule .* - [E=URL_SCHEME:http]
RewriteCond %{HTTPS} on
RewriteRule .* - [E=URL_SCHEME:https]

### Force www. prefix - (RECOMMENDED/OPTIONAL) SEO to prevent duplicate urls (uncomment to use)
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule ^(.*)$ %{ENV:URL_SCHEME}://www.%{HTTP_HOST}/$1 [R=301,L]

### Remove www prefix - Optional SEO to prevent duplicate urls (uncomment to use)
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ %{ENV:URL_SCHEME}://%1/$1 [R=301,L]

### Force HTTPS secure connections - Optional security (uncomment to use)
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

### Pass URL to permalinks dispatcher (do this last after any www or https redirects)
RewriteRule ^permalinks_dispatcher\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /cmsb/plugins/permalinks/permalinks_dispatcher.php [L]
</IfModule>
# END: CMS Permalink Code

Can you let me know if that works?  And if not, send CMS/FTP login details to dave@interactivetools.com and I can take a look and update the plugin if needed to work with Rackspace Cloud Sites.  (Note: Do not post passwords to the forum, email only).

Thanks!

Dave Edis - Senior Developer
interactivetools.com

By Steve99 - May 24, 2016 - edited: May 24, 2016

Hi Dave,

Okay, this particular CMSB version is 2.65 and we were running Permalinks plugin v1.02 - so I updated the Permalinks plugin to v1.03 (latest plugin for that release). Permalinks plugin v1.03 appears to have the latest htaccess code with the exception of the Permalinks Dispatcher rules placement (placed first versus last).

The preferred domain rules worked fine, but I did have to tweak the https condition check. Here is my updated htaccess file for CMSB v2.65 and Permalinks v1.03 that works with Rackspace Cloud Sites (issue resolved):

# START: CMS Permalink Code
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  ### Set URL_SCHEME (REQUEST_SCHEME isn't available before Apache < 2.4 and can include hostname)
  ### DEV NOTE: UPDATED CONDITION FOR RACKSPACE CLOUD SITES
  #RewriteCond %{HTTPS} off
  RewriteCond %{ENV:HTTPS} !on [NC]
  RewriteRule .* - [E=URL_SCHEME:http]
  ### DEV NOTE: UPDATED CONDITION FOR RACKSPACE CLOUD SITES
  #RewriteCond %{HTTPS} on
  RewriteCond %{ENV:HTTPS} on [NC]
  RewriteRule .* - [E=URL_SCHEME:https]
  
  ### Force www. prefix - (RECOMMENDED/OPTIONAL) SEO to prevent duplicate urls (uncomment to use)  
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^(.*)$ %{ENV:URL_SCHEME}://www.%{HTTP_HOST}/$1 [R=301,L]

  ### Remove www prefix - Optional SEO to prevent duplicate urls (uncomment to use)
  #RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  #RewriteRule ^(.*)$ %{ENV:URL_SCHEME}://%1/$1 [R=301,L]
  
  ### Force HTTPS secure connections - Optional security (uncomment to use)
  ### DEV NOTE: CONDITION DOES NOT WORK ON RACKSPACE CLOUD SITES
  #RewriteCond %{HTTPS} off
  ### DEV NOTE: UPDATED HTTPS CONDITION FOR RACKSPACE CLOUD SITES
  RewriteCond %{ENV:HTTPS} !on [NC]
  RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

  ### Pass URL to permalinks dispatcher (do this last after any www or https redirects)  
  RewriteRule ^permalinks_dispatcher\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /cmsb/plugins/permalinks/permalinks_dispatcher.php [L]
  
</IfModule>
# END: CMS Permalink Code

Thank you for your help on this.

Cheers,
Steve

By Dave - May 24, 2016

Hi Steve, 

Hmm, %{HTTPS} should work as it's part of the Apache spec.  It's an internal value set by mod_rewrite.  See "Specials" here: https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond

But %{ENV:HTTPS} should probably be pretty universally supported as well.  

Can you see if the original code I provided works if you just replace %{HTTPS} with %{ENV:HTTPS}
?

If so I'll update that in the plugin so it works next time you or anyone with Rackspace Cloud Sites upgrades.

Thanks!

Dave Edis - Senior Developer
interactivetools.com

By Steve99 - May 25, 2016

Hi Dave,

Just swapping out %{HTTPS} with %{ENV:HTTPS} alone did not work. With the load balancer coming into play, it appeared to have caused an endless loop.

Testing has revealed that only the following works on Rackspace Cloud Sites:

If SSL is not on
RewriteCond %{ENV:HTTPS} !on [NC]

If SSL is on
RewriteCond %{ENV:HTTPS} on [NC]

So using "off" versus "!on" doesn't work in this particular hosting environment.

Thanks again Dave!

Best Regards,
Steve

By Dave - May 26, 2016

Hi Steve, 

Ok, they may be pattern matching for certain text instead in the .htaccess file instead of actually using mod_rewrite.  They may have their own implementation for their cloud sites.

I've updated the plugin code generator to output this, which should work with their site, but I can't test it on my end.. Can you test it and let me know?

# Add this to an .htaccess file in your website root folder
# Your website root folder is usually named: htdocs, httpdocs, www, html, or just / in FTP

# START: CMS Permalink Code
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  ### Set URL_SCHEME (REQUEST_SCHEME isn't available before Apache < 2.4 and can include hostname)
  RewriteCond %{ENV:HTTPS} !on [NC]
  RewriteRule .* - [E=URL_SCHEME:http]
  RewriteCond %{ENV:HTTPS} on [NC]
  RewriteRule .* - [E=URL_SCHEME:https]

  ### Force www. prefix - (RECOMMENDED/OPTIONAL) SEO to prevent duplicate urls (uncomment to use)
  #RewriteCond %{HTTP_HOST} !^www\. [NC]
  #RewriteRule ^(.*)$ %{ENV:URL_SCHEME}://www.%{HTTP_HOST}/$1 [R=301,L]

  ### Remove www prefix - Optional SEO to prevent duplicate urls (uncomment to use)
  #RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  #RewriteRule ^(.*)$ %{ENV:URL_SCHEME}://%1/$1 [R=301,L]
  
  ### Force HTTPS secure connections - Optional security (uncomment to use)
  #RewriteCond %{ENV:URL_SCHEME} http
  #RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

  ### Pass URL to permalinks dispatcher (do this last after any www or https redirects)
  RewriteRule ^permalinks_dispatcher\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /cmsb/plugins/permalinks/permalinks_dispatcher.php [L]
</IfModule>
# END: CMS Permalink Code

Let me know if that works.  If so we'll put it in for the next plugin release.

Thanks!

Dave Edis - Senior Developer
interactivetools.com

By Dave - June 7, 2016

Hi Steve, 

Ok, can you try this one?  Here's the a latest: 

# Add this to an .htaccess file in your website root folder
# Your website root folder is usually named: htdocs, httpdocs, www, html, or just / in FTP

# START: CMS Permalink Code
<IfModule mod_rewrite.c>
  RewriteEngine On

  ### Manually detect URL Scheme (http or https). Cloud Servers & Load Balancers don't always give correct value
  ### ... of: HTTPS, REQUEST_SCHEME, SERVER_PORT, but ENV:HTTPS is sometimes manually set for us so we check both.
  RewriteCond %{HTTPS}     on [NC,OR]
  RewriteCond %{ENV:HTTPS} on [NC]
  RewriteRule .* - [E=URL_SCHEME:https,S=1]
  RewriteRule .* - [E=URL_SCHEME:http]

  ### Force www. prefix - (RECOMMENDED/OPTIONAL) SEO to prevent duplicate urls (uncomment to use)
  #RewriteCond %{HTTP_HOST} !^www\. [NC]
  #RewriteRule .* %{ENV:URL_SCHEME}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

  ### Remove www prefix - Optional SEO to prevent duplicate urls (uncomment to use)
  #RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  #RewriteRule .* %{ENV:URL_SCHEME}://%1%{REQUEST_URI} [R=301,L]
  
  ### Force HTTPS secure connections - Optional security (uncomment to use)
  #RewriteCond %{ENV:URL_SCHEME} http$ [NC]
  #RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

  ### Pass URL to permalinks dispatcher (do this last after any www or https redirects)
  RewriteRule ^permalinks_dispatcher\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /cmsb/plugins/permalinks/permalinks_dispatcher.php [L]
</IfModule>
# END: CMS Permalink Code

Let me know if that works.  Thanks!

Dave Edis - Senior Developer
interactivetools.com