APACHE_MODULES="actions alias auth_basic authn_file authz_host authz_groupfile authz_default authz_user autoindex cgi dir env expires include log_config mime negotiation setenvif ssl userdir php5 reqtimeout rewrite"APACHE_MODULES="actions alias auth_basic authn_file authz_host authz_groupfile authz_default authz_user autoindex cgi dir env expires include log_config mime negotiation setenvif ssl userdir php5 reqtimeout rewrite"
/etc/apache2/vhosts/MYDOMAIN.conf has these lines:
RewriteEngine On
RewriteOptions Inherit
RewriteCond %{HTTP_HOST} !^MYDOMAIN\.org$ [NC]
RewriteRule ^(.*)$ http://MYDOMAIN.org$1 [R=301,L] RewriteEngine On
This strips the “www” off when people put it there. So, according to /etc/sysconfig/apache2, the module is loading, but when I try to start apache, with that in my vhost config, I get this:
# apache2ctl start
Syntax error on line 47 of /etc/apache2/vhosts.d/MYDOMAIN.conf:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Is mod_rewrite installed?
Sure that the file you put it in is the right one? In all my webserver configs, the Rewrite stuff is done in .htaccess in the root folder of the site / domain.
If I go into yast software management and search for “rewrite”, I don’t see it anywhere. Where do I check to see if the mod is installed?
This worked on my last server, in the main httpd.conf file, where I specified all my vhosts. It’s more secure to do things in the main config file when you can, rather than a .htaccess file, so I moved it to there a long time ago. The only difference is that on this machine, I’m splitting up the vhosts into separate included conf files, while before, all my vhosts were specified in the main config file.
On my laptop (also used for webdevelopment) mod_rewrite is initiated in /etc/apache2/sysconfig.d/loadmodules.conf
I triggered that by setting up through Yast - Network services - HTTP server.
These days mod_rewrite is included in the apache2 package as installed by openSUSE.
But my 2 cents are that mod_rewrite doesn’t load, otherwise the error on RewriteEngine would not exist.
brasto1972 wrote:
> /etc/sysconfig/apache2 has this line:
>
>
> Code:
> --------------------
> APACHE_MODULES="actions alias auth_basic authn_file authz_host authz_groupfile authz_default authz_user autoindex cgi dir env expires include log_config mime negotiation setenvif ssl userdir php5 reqtimeout rewrite"APACHE_MODULES=“actions alias auth_basic authn_file authz_host authz_groupfile authz_default authz_user autoindex cgi dir env expires include log_config mime negotiation setenvif ssl userdir php5 reqtimeout rewrite”
> --------------------
>
>
> /etc/apache2/vhosts/MYDOMAIN.conf has these lines:
>
>
> Code:
> --------------------
> RewriteEngine On
> RewriteOptions Inherit
> RewriteCond %{HTTP_HOST} !^MYDOMAIN.org$ [NC]
> RewriteRule ^(.*)$ http://MYDOMAIN.org$1 [R=301,L] RewriteEngine On
> --------------------
Why does the fourth line, which starts ‘RewriteRule’ contain the text
‘RewriteEngine On’ at the end? IT would appear to be likely to prompt an
error like that you describe.
> This strips the “www” off when people put it there. So, according to
> /etc/sysconfig/apache2, the module is loading, but when I try to start
> apache, with that in my vhost config, I get this:
>
>
> Code:
> --------------------
> # apache2ctl start
> Syntax error on line 47 of /etc/apache2/vhosts.d/MYDOMAIN.conf:
> Invalid command ‘RewriteEngine’, perhaps misspelled or defined by a module not included in the server configuration
> --------------------
>
>
> So, what am I missing?
>
> Thank you,
>
> Brandon
PS The .htaccess thing is a red herring. You can and should configure
all this in the config files as you are doing, if you can on your host.
If you installed apache2 from the openSUSE packages, mod_rewrite is part of “apache2” so you have it installed for sure.
You can check if you have the file mod_rewrite.so in /usr/lib64/apache2 (or /usr/lib/apache2 on a 32bit system).
But I guess you would get a different error message then or apache2 wouldn’t start even.
Your APACHE_MODULES= line in your first post looks strange. Was this just a copy/paste error or does it really look like this?
Also, /etc/apache2/vhosts/MYDOMAIN.conf seems to be missing a newline (or the RewriteEngine is superfluous there):
RewriteEngine On
RewriteOptions Inherit
RewriteCond %{HTTP_HOST} !^MYDOMAIN\.org$ [NC]
RewriteRule ^(.*)$ http://MYDOMAIN.org$1 [R=301,L] RewriteEngine On
Good catch. That was a paste error here in the forum. Everything after the “]” symbol on the fourth line above was not actually in the config file. When I pasted the code, it somehow pasted twice, and when I deleted the second paste, I missed removing that second “RewriteEngine On”. Found the solution though. I needed to add this line:
Good catches. Those were both paste errors here in the forum. The APACHE_MODULES= line was one I didn’t catch. In the vhosts/MYDOMAIN.conf file, I did catch most of it, but missed the second RewriteEngine On after the “]” symbol. Everything after the “]” symbol on that line was not actually in the config file. When I paste via middle click, for some reason, I randomly get a double paste sometimes. When I deleted the second paste, I missed removing that second “RewriteEngine On”.
Found the solution though. I needed to add this line:
A small lesson: Use Yast to configure server/services. If you check Yast - Network services - HTTP server, there’s a tab “Server modules”, which shows all the available modules and their status. Rewrite by default is off. If you set it to “On”, Yast takes care that the setting is writen in the proper config file(s), plus a restart of the apache service.
I’m an old school UNIX trained sysadmin, and found, find, and will find Yast a blessing. No editting, no chance of typos¸ no hitting deprecated config files, it just works.
BTW, I agree on .htaccess being a bit of a red herring. Keeping the stuff in the config files for httpd and vhosts makes more sense.