Setting up friendly URL in production mode

I am experiencing a Plone url rewrite problem with my Virtual Hosting setup: Debian, Apache2 and a Plesk web admin setup. I have a website http://openbeam.net which I’d like to re-direct to my plone instance
http://falcon296.startdedicated.com:8084/openbeam

Following the advice of https://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2
I put the Plone rewrite rule on a file that can cause the rewrite to happen. The file is:
/var/www/vhbosts/openbeam.net/httpdocs/.htaccess

I had made sure the mod_rewrite is on and works. I knew that because I had tested it with the following rule:

RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^openbeam.net [OR] RewriteCond %{HTTP_HOST} ^www.openbeam.net RewriteRule ^(.*) http://falcon296.startdedicated.com:8084/openbeam

Running the above rule simply jumps the url to the destination url.

But when I paste in

RewriteEngine On
RewriteRule ^/(.*) http://127.0.0.1:8084/VirtualHostBase/http/openbeam.net:80/openbean/VirtualHostRoot/$1 [L,P]

The rule did not work.

I have tried putting the rewrite rule in other Apache2 configure structure such as: /etc/apache2/sites-enabled/openbeam.net.conf

As suggested on the plone documentation https://docs.plone.org/manage/deploying/front-end/apache.html

" ... Add virtual host config file /etc/apache2/sites-enabled/yoursite.conf. Assuming Plone is your site id in Zope Management Interface (capital lettering do matter) and your domain name is yoursite.com ...."

to no avail.

I have previously run my plone production on CentOS/Plesk/Apache the plone rewrite rule worked with no problem. Has anyone seen the same problem?

Is the site ID "openbean" misspelled?

...and yeah I would refer to the official docs first. The Stack Overflow question you referred to first was from 2009.

Kim, it's misspelled when I created my forum post. It is correctly spelled openbeam on the .htaccess file

I've never seen anyone use the .htaccess file that way. A more typical file in which to put rewrite rules for Apache would be called /etc/apache2/sites-enabled/openbeam.net.conf but it will depend on your system.

I have put the plone rewrite code /etc/apache2/sites-enabled/openbeam.net.conf there as well. It didn't work.

In fact, even when I put the following code :

UseCanonicalName On

NameVirtualHost *
<VirtualHost *>
ServerAlias openbeam.net
ServerSignature On

Header set X-Frame-Options "SAMEORIGIN"
Header set Strict-Transport-Security "max-age=15768000; includeSubDomains"
Header set X-XSS-Protection "1; mode=block"
Header set X-Content-Type-Options "nosniff"
Header set Content-Security-Policy-Report-Only "default-src 'self'; img-src *; style-src 'unsafe-inline'; script-src 'unsafe-inline' 'unsafe-eval'"

ProxyVia On

# prevent your web server from being used as global HTTP proxy
<LocationMatch "^[^/]">
  Deny from all
</LocationMatch>

<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>
# The following code works if I put in /var/www/vhosts/openbeam.net/httpdocs/.htaccess          
RewriteEngine On
      
RewriteCond %{HTTP_HOST} ^openbeam.net [OR]
 
RewriteCond %{HTTP_HOST} ^www.openbeam.net 

 
RewriteRule ^(.*) http://falcon296.startdedicated.com:8084/openbeam 

<VirtualHost *>
ServerAlias *
ServerRoot /var/www
ServerSignature On

RewriteEngine On

RewriteBase /
RewriteCond %{HTTP_HOST} ^openbeam.net [OR]
 
RewriteCond %{HTTP_HOST} ^www.openbeam.net 

 
RewriteRule ^(.*) http://falcon296.startdedicated.com:8084/openbeam 

worked in /var/www/vhosts/openbeam.net/httpdocs/.htaccess

The rewrite does not take place. It's as if my set up is such that rewrite works only in var/www/vhosts/openbeam.net/httpdocs/.htaccess

It would help to see the Apache log messages to understand why it's not working. Also would help to see your Apache configuration file.

What I stumbled upon is that for unknown reason, my Apache2 config is such that
the RewriteRule ^/(.) pattern does not fire the rewrite . When I replaced it with ^(.) ie, the "/" has been elimiated then the pattern will trigger.

What I have now in the .htaccess file is
RewriteRule ^(.*) http://localhost:8084/VirtualHostBase/http/%{HTTP_HOST}:80/openbeam/VirtualHostRoot/$1 [P,L]

By doing that a url like: http://openbeam.net/beamprojects and http://openbeam.net/infocenter get properly redirected without explosing the long url. However, the rewrite pattern is such that openbeam.org and its Home tab is not referencing the right place. I need to figure out a rewrite rule for the case when there is no child.

And also I have absolutely no idea why my Rewrite engine works differently.

Maybe you could paste here your complete Apache configuration?

It turns out for my Plesk, Debian, Apache2 configuration, I had to put my rewrite rule in
/var/www/vhosts/system/xxx/conf/httpd.conf file. This file was initially generated by Plesk admin console when I add a doman or subdomain via Plesk. /etc/apache2/sites-enabled/xxx.conf has no effect on my system. I cannot explain why. All I know is that it works.

1 Like