Operating System - Linux
1753766 Members
5616 Online
108799 Solutions
New Discussion юеВ

apache + redhat + mod_rewrite

 
SOLVED
Go to solution
Piotr Kirklewski
Super Advisor

apache + redhat + mod_rewrite

Hi there
There is something wrong with my apache:

LoadModule rewrite_module modules/mod_rewrite.so

And in vhost.conf :

DocumentRoot /home/default/mysite.com/user/htdocs

My .htaccess looks like that:

eader append P3P "CP=\"PHY DEM ONL STA NAV COM OUR CURi ADM DEV TAI CAO COR BUS DSP\""
RewriteEngine On
rewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(php|html?)\ HTTP/
rewriteRule ^index\.(php|html?)$ http://loansloansloansuk.com/ [R=301,L]
#
rewriteCond %{HTTP_HOST} ^www.mysite.com\.com
rewriteRule (.*) http://mysite.com/$1 [R=301.L]
ErrorDocument 400 http://mysite.com
ErrorDocument 401 http://mysite.com
ErrorDocument 403 http://mysite.com
ErrorDocument 404 http://mysite.com
ErrorDocument 500 http://mysite.com

And rewriting is not working:

Can anyone help ?







Jesus is the King
5 REPLIES 5
sshakthi
Advisor
Solution

Re: apache + redhat + mod_rewrite

Generally speaking, you should put the rewrite directives inside the vhost entry for the site. If you put it in the main configuration file, the rewrite will affect all domains under control of the server. Here's a list of the rewrites I'm using on one of my domains. Use them as examples for fine-tuning the rules I provided above. The log can be a great help when you're trying to figure out why it isn't working.

# turn on the mod_rewrite engine and set the log
# if you want to debug, the log level should be set higher (I use '9')
RewriteEngine On
RewriteLogLevel 0
RewriteLog /var/log/rewrite.log

# rewrite entry for TRACE methods
# TRACE methods can be leveraged to create a vulnerability and do not
# serve any real purpose...disabling them is a good idea
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]

# rewrite to mydomain..com, regardless of incoming domain
# I host several aliases on the same domain, but want the URL to always
# read the 'real' domain name. This section takes care of that.
RewriteCond %{HTTP_HOST} !^www\.mydomain.\.com [NC]
RewriteCond %{HTTP_HOST} !^webmail\.mydomain\.com [NC]
RewriteRule ^/(.*) https://www.mydomain..com/$1 [L,R]

# This entry ensures I never have a blank filename
# It's a particular requirement due to how I've built my content management system.
RewriteCond %{SCRIPT_FILENAME} ^/$
RewriteCond %{HTTP_HOST} !^webmail\.mydomain\.com [NC]
RewriteRule ^/$ https://www.mydomain.com/index.php [L,R]

# rewrite for category pages
# This matches any URL like https://www.mydomain.com/catalog/a_category_name
# and rewrites it to https://www.mydomain.com/cat_list.php?cid=
# /etc/httpd/conf/rewrite.mydomain.txt is a text file used as a conversion map
RewriteMap catlist txt:/etc/httpd/conf/rewrite.mydomain.txt
RewriteRule ^/catalog/(.+)\.html /${catlist:$1} [NC]

# These entries used for disabling the site
# First IP entry is office T1, second is home
# These entries stay commented until I have to take the site down for some kind of extended
# maintenance. The two IP conditions allow me to see the normal site from 2 specific locations.
# RewriteCond %{SCRIPT_FILENAME} ^/(.+)\.php [NC]
# RewriteCond %{SCRIPT_FILENAME} !^/maintenance.php [NC]
# RewriteCond %{REMOTE_ADDR} !^11\.22\.33\.44
# RewriteCond %{REMOTE_ADDR} !^55\.66\.77\.88
# RewriteRule ^/(.*) https://www.mydomain.com/maintenance.php [L,R]

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html


sshakthi
Advisor

Re: apache + redhat + mod_rewrite

Piotr Kirklewski
Super Advisor

Re: apache + redhat + mod_rewrite

Hi there

I have small problem with rewrite again:
Everythink worksfine but when I'm starting apache I get this error:

cannot use a full URL in a 401 ErrorDocument directive --- ignoring!

Whats up ?

Cheers
Jesus is the King
Piotr Kirklewski
Super Advisor

Re: apache + redhat + mod_rewrite

My file (rewrite.conf) looks like that:

Header append P3P "CP=\"PHY DEM ONL STA NAV COM OUR CURi ADM DEV TAI CAO COR BUS DSP\""
RewriteEngine On
rewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(php|html?)\ HTTP/
rewriteRule ^index\.(php|html?)$ http://ttt.com/ [R=301,L]
#
rewriteCond %{HTTP_HOST} ^www.ttt.com\.com
rewriteRule (.*) http://ttt.com/$1 [R=301.L]
ErrorDocument 400 http://ttt.com
ErrorDocument 401 http://ttt.com
ErrorDocument 403 http://ttt.com
ErrorDocument 404 http://ttt.com
ErrorDocument 500 http://ttt.com
Jesus is the King
Ivan Ferreira
Honored Contributor

Re: apache + redhat + mod_rewrite

According to the message:

cannot use a full URL in a 401 ErrorDocument directive --- ignoring!

The directive:

ErrorDocument 401 http://mysite.com

Is not correct, does not like a full URL. You should try something like:

ErrorDocument 401 /subscription_info.html
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?