I was wondering if somebody could help me with an Apache re-write rule. Apparently CentOS 6.8 is running apache-2.2.15-53. I am trying to redirect all pages except for two pages. The apache rewrite directives in the httpd config are:
RewriteEngine on RewriteCond %{REQUEST_URI}!^/test/ RewriteCond %{REQUEST_URI}!^/my-folder/ RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
These commands should cause all requests to get re-directed to www.newdomain.com except for those with a /test or /my-folder on the end of the URL. However when I place these commands into the the httpd config apache spits out this error message:
Starting httpd: Syntax error on line 31 of /etc/httpd/conf.d/olddomain.conf: RewriteCond: bad argument line '%{REQUEST_URI}!^/test/
I have of course renamed the real config parameters. Can somebody tell me if these directives only work in apache-2.4 and if so how do I do the same thing in apache-2.2? If these directives should work in apache-2.2 is this an apache problem?
Thanks for your help.
On 28.05.2016 21:03, Paul R. Ganci wrote:
I was wondering if somebody could help me with an Apache re-write rule. Apparently CentOS 6.8 is running apache-2.2.15-53. I am trying to redirect all pages except for two pages. The apache rewrite directives in the httpd config are:
RewriteEngine on RewriteCond %{REQUEST_URI}!^/test/ RewriteCond %{REQUEST_URI}!^/my-folder/ RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
These commands should cause all requests to get re-directed to www.newdomain.com except for those with a /test or /my-folder on the end of the URL. However when I place these commands into the the httpd config apache spits out this error message:
^ is the beginning marker of a regular expression; are you sure you want at the end?
RewriteEngine on RewriteCond %{REQUEST_URI} !^/test/ RewriteCond %{REQUEST_URI} !^/my-folder/ RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
Starting httpd: Syntax error on line 31 of /etc/httpd/conf.d/olddomain.conf: RewriteCond: bad argument line '%{REQUEST_URI}!^/test/
caused by missing whitespace
I have of course renamed the real config parameters. Can somebody tell me if these directives only work in apache-2.4 and if so how do I do the same thing in apache-2.2? If these directives should work in apache-2.2 is this an apache problem?
these should work in 2.2.x, too;
Am 28.05.2016 um 21:03 schrieb Paul R. Ganci:
I was wondering if somebody could help me with an Apache re-write rule. Apparently CentOS 6.8 is running apache-2.2.15-53. I am trying to redirect all pages except for two pages. The apache rewrite directives in the httpd config are:
RewriteEngine on RewriteCond %{REQUEST_URI}!^/test/ RewriteCond %{REQUEST_URI}!^/my-folder/ RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
These commands should cause all requests to get re-directed to www.newdomain.com except for those with a /test or /my-folder on the end of the URL. However when I place these commands into the the httpd config apache spits out this error message:
Starting httpd: Syntax error on line 31 of /etc/httpd/conf.d/olddomain.conf: RewriteCond: bad argument line '%{REQUEST_URI}!^/test/
You missed a whitespace between the server variable %{REUQEST_URI} and the value you test against. In both cases you did. And you probly want a trailing [OR] parameter. See
https://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond
I have of course renamed the real config parameters. Can somebody tell me if these directives only work in apache-2.4 and if so how do I do the same thing in apache-2.2? If these directives should work in apache-2.2 is this an apache problem?
Works with Apache 2.2, see cited docs above.
Thanks for your help.
Alexander
On 05/28/2016 01:35 PM, Alexander Dalloz wrote:
Am 28.05.2016 um 21:03 schrieb Paul R. Ganci:
Starting httpd: Syntax error on line 31 of /etc/httpd/conf.d/olddomain.conf: RewriteCond: bad argument line '%{REQUEST_URI}!^/test/
You missed a whitespace between the server variable %{REUQEST_URI} and the value you test against. In both cases you did. And you probly want a trailing [OR] parameter. See
https://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond
I did the suggested changes and indeed the syntax error goes away but the code does not work. The redirection takes place for all the pages even for those specified in the RewriteCond lines. My immediate syntax error problem is solved. It is funny how I stared at these lines for what seemed like eons and my mind fixed the immediate problem.
Thanks for your help, Alexander. I will take another look at what I did and see if I can't find what else is wrong.
Am 28.05.2016 um 22:08 schrieb Paul R. Ganci:
On 05/28/2016 01:35 PM, Alexander Dalloz wrote:
Am 28.05.2016 um 21:03 schrieb Paul R. Ganci:
Starting httpd: Syntax error on line 31 of /etc/httpd/conf.d/olddomain.conf: RewriteCond: bad argument line '%{REQUEST_URI}!^/test/
You missed a whitespace between the server variable %{REUQEST_URI} and the value you test against. In both cases you did. And you probly want a trailing [OR] parameter. See
https://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond
I did the suggested changes and indeed the syntax error goes away but the code does not work. The redirection takes place for all the pages even for those specified in the RewriteCond lines. My immediate syntax error problem is solved. It is funny how I stared at these lines for what seemed like eons and my mind fixed the immediate problem.
Thanks for your help, Alexander. I will take another look at what I did and see if I can't find what else is wrong.
May I suggest you enable special logging for the mod_rewrite activity?
https://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog https://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteloglevel
(Btw. that has changed with Apache 2.4)
With a dedicated logging of what happens for rewrites you should be able to detect what is different to your intention.
Alexander
On 05/28/2016 02:26 PM, Alexander Dalloz wrote:
May I suggest you enable special logging for the mod_rewrite activity?
https://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog https://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteloglevel
Yes this is a good idea.
On Sat, 2016-05-28 at 13:03 -0600, Paul R. Ganci wrote:
..........
How about
RewriteEngine on RewriteCond %{REQUEST_URI} !^/test/ [NC] RewriteCond %{REQUEST_URI} !^/my-folder/ [NC] RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
or
RedirectMatch 301 ^/test/(.*)$ /test2/$1 RedirectMatch 301 ^/my-folder/(.*)$ /my-folder2/$1 RedirectMatch 301 ^(.*)$ http://new.domain.com/$1
or
RedirectMatch 301 ^/usual-directories-names-prefix/(.*)$ http://new.domain.com/new-directory-names-prefix$1
For many years the practise of using the 'www' prefix has been depreciated by using just the domain name but also having a DNS A record for the www for those that love the 'www' prefix.
Having a directory names prefix helps enormously when maintaining multiple web sites.
Many web sites have a confused illogical jumble of directory names, and many of those are far too long. Good planing before going live will subsequently save lots of time and effort. Keep the public directory structure plain, simple and logical. One never ever needs URL's exceeding 80 characters.
Avoid things like this
http://www/domain.com/public-communications/press-and-public/press-releases/...
and
http://www.dailymail.co.uk/news/article-3615099/Outrage-directed-parents-Har...
If anyone has to type-in one of your URLs they will definitely appreciate short URLs where there is less chance of making spelling mistakes.
On Sun, 2016-05-29 at 17:33 +0100, Always Learning wrote:
RedirectMatch 301 ^(.*)$ http://new.domain.com/$1
should be:-
RedirectMatch 301 ^/(.*)$ http://new.domain.com/$1