0

I am trying to set up a distributed web farm using apache2. Before deploying the configuration to my other 3 servers, I wanted to get everything to work on the first one (designated P-WEB-01) at 10.0.2.1. I have multiple sites set up through virtual hosts, and the different domain names are all working properly.

However, my problem is with apache_mod_rewrite, where I'm attempting to set up a url that looks like this : http://example.com/firstvariable/secondvariable/thirdvaraible and have it read by the PHP script (index.php) as http://example.com/index.pp?a=firstvariable&b=secondvariable&c=thirdvariable. The system also has to be set up in a way where the mod_rewrite ignores internal file names and directories, as they are proxied to the external site (for security purposes) through the script.

I had this script running on an IIS7 server for a while, and it worked perfectly fine. Also, I have followed the whole a2enmod mod_rewrite, which outputted success. I enabled AllowOverride All in apache2.conf, and set up the sites .htaccess file in the site's root directory, and had it say:

RewriteEngine on
RewriteRule ^index.php$ index.html

which still did nothing.

  • I've restarted apache, as well as the entire server – Tim Powell Jul 1 '14 at 18:58
  • You have to write more sophisticated re-write. digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite – Panther Jul 1 '14 at 19:06
  • RewriteRule ^example.com/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ example.com/index.php?a=$1&b=$2&c=3[NC] assuming your php script will validate the input and handle empty variables ;) – Panther Jul 1 '14 at 19:09
  • The problem is not the rewrite script, although I will for sure use some direvation of the script written in the last comment. My problem is that, for some reason, mod_rewrite will not even activate. I tried a simple script: ^index.php$ index.html and it would output "404 index.html not found" – Tim Powell Jul 1 '14 at 19:16
  • Nothing is matching ^index.php . Your example url is " example.com/firstvariable/secondvariable/thirdvaraible" . Nothing in your example url matches "index.php" , let alone ^index.php . I suggest you either read up on regular expressions or post the actual url you want us to debug. Otherwise I would say fix $your_expression – Panther Jul 1 '14 at 19:20
1

I used

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([\w.]+)/?$ index.php?a=$1 [L,QSA]
RewriteRule ^(\w+)/([\w.]+)/?$ index.php?a=$1&b=$2 [L,QSA]
RewriteRule ^(\w+)/(\w+)/([\w.]+)/?$ index.php?a=$1&b=$2&c=$3 [L,QSA]

As well as made sure my firewall (IPTables-based) was actually forwarding to the correct (new) webserver.

Thanks everyone! :)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.