mod-rewrite problem

theplayer

Verified User
Joined
Jan 26, 2009
Messages
69
For a cms system i must have friendly URL option and turn on and config the mod_rewrite module. I have Debian 5 and DA newest version. Don't know if i have to enable this option because i think its enabled standard?

Also i have this code in the .htaccess but the mod-rewrite module doenst seems to be work. All links are dead. What can be wrong ?


Code:
Options All -Indexes
ErrorDocument 404 /404.php
FileETag MTime Size

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^sitemap\.xml$ index.php [L]
RewriteRule ^(.*)(\.html|\.htm)$ index.php [L]
RewriteRule ^(.*)(\.rss|\.atom|\.txt)$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php [L]
</IfModule>

<IfModule mod_expires.c>
	ExpiresActive on
	ExpiresByType image/gif "access plus 1 months"
	ExpiresByType image/jpeg "access plus 1 months"
	ExpiresByType image/png "access plus 1 months"
	ExpiresByType text/css "access plus 1 months"
	ExpiresByType application/x-javascript "access plus 1 months"
</IfModule>
 
hmmm in /etc/httpd/conf/httpd.conf file there is no line where i find mod_rewrite.... So i must install it first i think ?
 
My .htaccess file is above. This file works on a other servers... So i think its not (good) enabled. Is there a way to check if its renabled and runns correctly?

No, it is enabled as standard, I use friendly url too and have never edited som files.

Your .htaccess is may be broken/uncorrect
 
If the .htaccess has an error you should get a 500 error when you try to access the website. Is that the case?

You can check if mod_rewrite is compiled in with Apache doing:
Code:
httpd -l

If it's not then you should re-compile Apache.

You could also enable mod_rewrite logging:
Code:
RewriteLog "/var/log/httpd/rewrite.log"
RewriteLogLevel 9 # Maximum debug level, should be disabled on production environment

Note that this must be added on the VirtualHost or at the httpd.conf and *NOT* in the .htaccess.

After this you can check the file /var/log/httpd/rewrite.log to see what happens when you try to access an URL that should be rewritten.
 
Its enabled:

Code:
Compiled in modules:
  core.c
  mod_authn_file.c
  mod_authn_default.c
  mod_authz_host.c
  mod_authz_groupfile.c
  mod_authz_user.c
  mod_authz_default.c
  mod_auth_basic.c
  mod_include.c
  mod_filter.c
  mod_deflate.c
  mod_log_config.c
  mod_logio.c
  mod_env.c
  mod_headers.c
  mod_unique_id.c
  mod_setenvif.c
  mod_version.c
  mod_proxy.c
  mod_proxy_connect.c
  mod_proxy_ftp.c
  mod_proxy_http.c
  mod_proxy_scgi.c
  mod_proxy_ajp.c
  mod_proxy_balancer.c
  mod_ssl.c
  prefork.c
  http_core.c
  mod_mime.c
  mod_dav.c
  mod_status.c
  mod_autoindex.c
  mod_asis.c
  mod_suexec.c
  mod_cgi.c
  mod_dav_fs.c
  mod_dav_lock.c
  mod_negotiation.c
  mod_dir.c
  mod_actions.c
  mod_userdir.c
  mod_alias.c
  [B][COLOR="Red"]mod_rewrite.c[/COLOR][/B]
  mod_so.c
 
Ok, that's important.
Did you check the other stuff I mentioned? Are you getting 500 HTTP errors? Did you enable logging?
Which version of Apache are you running? I think mod_rewrite for Apache 1.3 is much more limited in the regular expressions it lets you use.
 
If i enable the option i get a 404

I run Apache 2.2.14

Ok, that means the .htaccess is fine and Apache is not having problems processing it. Now you should enable mod_rewrite logs and check what happens there.
 
ok i will enable this. so just add this lines in my httpd.conf ?

Code:
RewriteLog "/var/log/httpd/rewrite.log"
RewriteLogLevel 9 # Maximum debug level, should be disabled on production environment


Ok, that means the .htaccess is fine and Apache is not having problems processing it. Now you should enable mod_rewrite logs and check what happens there.
 
Yes. Then restart apache, enable the friendly URLs, try them and check the log to see what happened.
 
i have added it to: /etc/httpd/httpd.conf

In DA adminpanel i stopt httpd and then i start it. But if i want to start it i get an error that it can't start.

If i delete the above code in /etc/ httpd/httpd.conf, httpd starts again....:confused:
 
Check /var/log/httpd/error_log to see the error why it cannot start. You might have to create the log file:

Code:
touch /var/log/httpd/rewrite.log
chown apache:apache /var/log/httpd/rewrite.log
 
This is log file:

Code:
[Tue Dec 29 00:12:01 2009] [notice] caught SIGTERM, shutting down
[Tue Dec 29 00:12:04 2009] [warn] RSA server certificate CommonName (CN) `localhost' does NOT match server name!?
[Tue Dec 29 00:12:04 2009] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Tue Dec 29 00:12:04 2009] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Dec 29 00:12:05 2009] [warn] RSA server certificate CommonName (CN) `localhost' does NOT match server name!?
[Tue Dec 29 00:12:05 2009] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Tue Dec 29 00:12:05 2009] [notice] Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8g DAV/2 configured -- resuming normal operations
[Tue Dec 29 09:41:37 2009] [notice] caught SIGTERM, shutting down
[Tue Dec 29 09:42:49 2009] [warn] RSA server certificate CommonName (CN) `localhost' does NOT match server name!?
[Tue Dec 29 09:42:49 2009] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Tue Dec 29 09:42:49 2009] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Dec 29 09:42:50 2009] [warn] RSA server certificate CommonName (CN) `localhost' does NOT match server name!?
[Tue Dec 29 09:42:50 2009] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Tue Dec 29 09:42:50 2009] [notice] Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8g DAV/2 configured -- resuming normal operations
[Tue Dec 29 12:23:30 2009] [error] [client 201.238.235.11] File does not exist: /var/www/html/mysql
[Tue Dec 29 12:23:30 2009] [error] [client 201.238.235.11] File does not exist: /var/www/html/404.shtml


Check /var/log/httpd/error_log to see the error why it cannot start. You might have to create the log file:

Code:
touch /var/log/httpd/rewrite.log
chown apache:apache /var/log/httpd/rewrite.log
 
Code:
[Tue Dec 29 09:42:50 2009] [notice] Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8g DAV/2 configured -- resuming normal operations

According to this Apache should be running. Check if there are processes of Apache running with:

Code:
ps -ef |grep httpd
 
This is the output:

Code:
apache     662 29843  0 05:16 ?        00:00:00 /usr/sbin/httpd -k start -DSSL
apache     673 29843  0 05:16 ?        00:00:00 /usr/sbin/httpd -k start -DSSL
root      3080  3075  0 11:07 pts/0    00:00:00 grep httpd
root     29843     1  0 00:13 ?        00:00:00 /usr/sbin/httpd -k start -DSSL
apache   29848 29843  0 00:13 ?        00:00:00 /usr/sbin/httpd -k start -DSSL
apache   29849 29843  0 00:13 ?        00:00:00 /usr/sbin/httpd -k start -DSSL
apache   29889 29843  0 00:22 ?        00:00:00 /usr/sbin/httpd -k start -DSSL
apache   32573 29843  0 04:00 ?        00:00:00 /usr/sbin/httpd -k start -DSSL
apache   32574 29843  0 04:00 ?        00:00:00 /usr/sbin/httpd -k start -DSSL
apache   32576 29843  0 04:00 ?        00:00:00 /usr/sbin/httpd -k start -DSSL
apache   32577 29843  0 04:00 ?        00:00:00 /usr/sbin/httpd -k start -DSSL
apache   32583 29843  0 04:00 ?        00:00:00 /usr/sbin/httpd -k start -DSSL
 
Im having issues where my mod_rewrite isnt even installed!

When i do httpd -l it says command not found.

How can i install this
 
ok thnx!

So if i have some issues with mod-rewrite things in a cms system such as friendly url's and captcha codes, its not because it's not working or install'd on the server but there is some (mis)configuration / code in the cms system ?

That means apache is running...
 
Yes, there should be some problem with the .htaccess. You should check the rewrite.log file.
 
Back
Top