Solved

help with rewrite rules

Posted on 2007-04-03
19
208 Views
Last Modified: 2010-03-04
In my Google Webmasters account, i get these 4 URLs as 404 page not found errors:

http://www.quest-recruiting.com/advertise/167-lead-cost-engineer-%ef%bf%bd-early-works/const./
http://www.quest-recruiting.com/apply/167-lead-cost-engineer-%ef%bf%bd-early-works/const./
http://www.quest-recruiting.com/print/162-project-engineer-%EF%BF%BD-gas-processing-and-export/
http://www.quest-recruiting.com/print/167-lead-cost-engineer-%ef%bf%bd-early-works/const./

However the correct URL for this Job is:

http://www.quest-recruiting.com/advertise/167-lead-cost-engineer---early-works---const./

In my htaccess file i have this, but it isn't working:

RewriteRule ^advertise/167-lead-cost-engineer---early-works/const./$ /advertise/167-lead-cost-engineer---early-works---const./? [R=301,L]
RewriteRule ^advertise/167-lead-cost-engineer-%ef%bf%bd-early-works/const./$ /advertise/167-lead-cost-engineer---early-works---const./? [R=301,L]
0
Comment
Question by:ellandrd
  • 10
  • 9
19 Comments
 
LVL 27

Expert Comment

by:Nopius
ID: 18856065
1) %ef%bf%bd is not the same as %EF%BF%BD, correct binary string enconing is done with capital letters '%EF%BF%BD'
2) Matching binary strings in RewriteRule pattern quite different.

Here is my test configuration for %EF%BF%BD:
RewriteEngine On
RewriteBase /
RewriteRule ^test/index.html\357\277\275$ test/index.html [R=301,L,NE]

I put these lines in document root .htaccess.
Then, when I try to access http://myserver/test/index.html%EF%BF%BD
I get into http://myserver/test/index.html
\357 is an octal representation of %EF, that's the only way to match against binary characters.
NE flag stands for No Escape

3) What for do you need this rule?:
RewriteRule ^advertise/167-lead-cost-engineer---early-works/const./$ /advertise/167-lead-cost-engineer---early-works---const./? [R=301,L]

It seems to me it does nothing.

4) What is a RewriteBase and a context of RewriteRules (is it in virtual host/directory/global/.htaccess)?

0
 
LVL 16

Author Comment

by:ellandrd
ID: 18856083
>>1) %ef%bf%bd is not the same as %EF%BF%BD, correct binary string enconing is done with capital letters '%EF%BF%BD'
2) Matching binary strings in RewriteRule pattern quite different.

obviously i didnt know this otherwise i would have fixed it myself... but its nice to know now...

>>RewriteRule ^advertise/167-lead-cost-engineer---early-works/const./$ /advertise/167-lead-cost-engineer---early-works---const./? [R=301,L]

if you look closely, you'll see the first URL has  a "/" in the end of it.  the slashes break my site so i redirect to second URL which replaces the "/" with a "-".

>>4) What is a RewriteBase and a context of RewriteRules (is it in virtual host/directory/global/.htaccess)?

the .htaccess is under:

/public_html/root-folder/.htaccess

all files exist under: public_html/root-folder/ so i guess the rewritebase is /
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18856117
still dont work... getting 404 not found..

try the urls from above again...

here is my .htaccess file:

http://www.quest-recruiting.com/htaccess.txt
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 27

Expert Comment

by:Nopius
ID: 18856137
Now we should enable rewrite rule log engine in main httpd.conf with these global options:
RewriteEngine On
RewriteLog /tmp/rewrite.log
RewriteLogLevel 5

Then restart apache, then try to  access http://www.quest-recruiting.com/print/162-project-engineer-%EF%BF%BD-gas-processing-and-export/
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18856169
i cant restart apache - i have no access to server.
0
 
LVL 27

Expert Comment

by:Nopius
ID: 18856172
I tried to access this URL form telnet. It seems I get incorrect redirection because of your very first line:
RewriteRule ^(.*)$ http://www.quest-recruiting.com/$1 [R=301,L]

Which matches any request and redirects me to the same URL...
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18856187
will i remove this?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18856193
ok i have it removed...
0
 
LVL 27

Expert Comment

by:Nopius
ID: 18856195
Yes, backup your htaccess and remove this rule, Also append "RewriteBase /"
0
 
LVL 27

Expert Comment

by:Nopius
ID: 18856199
I have no time today. Now you may see inside logs and paste them here. I'll see tomorrow.
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18856207
ok
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18856218
when i add them log lines im getting Internal Server Error....
0
 
LVL 27

Expert Comment

by:Nopius
ID: 18856507
Log lines should be in httpd.conf global section, not in .htaccess
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18856511
ok - well like i said - i dont have access to the server so i cant make these changes...
0
 
LVL 27

Expert Comment

by:Nopius
ID: 18856552
without logs it will be difficult. I'll try to reproduce exactly yours .htaccess tomorrow and see logs.
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18868943
any luck?
0
 
LVL 27

Expert Comment

by:Nopius
ID: 18869143
Hi, again.
I loaded your config on my server. When trying to access  http://localhost/print/162-project-engineer-%EF%BF%BD-gas-processing-and-export/

I see an error:
127.0.0.1 - - [07/Apr/2007:21:21:51 +1100] [localhost/sid#81237f0][rid#82d6050/initial] (3) [per-dir /u10/v/vA0/usr/htdocs/] applying pattern '^print/162-project-engineer-\357\277\275-gas-processing-and-export/$' to uri 'print.php/162-project-engineer-О©Ґ-gas-processing-and-export/'

You may notice that rewrite engine is matching against print.php/, not print/, but I entered print/...
That's because you have a rule 'RewriteRule ^print/([^/]+)/?$ print.php?jobid=$1 [nc]' before these rules (just place it at the end of all ^print/ rewrite rules). But there may be other errors, that I missed.
Without having access to httpd.conf and rewrite log it might be quite difficult to find all errors.
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18869974
still didnt work.
0
 
LVL 27

Accepted Solution

by:
Nopius earned 500 total points
ID: 18870701
It works here, but I don't have appropriate print.php script to perform further testing. I just moved rewrite rule with print.php after all ^print/ rules in .htaccess.

That's are my logs:
127.0.0.1 - - [08/Apr/2007:09:39:47 +1100] [localhost/sid#81237f0][rid#82f8050/initial] (3) [per-dir /u10/v/vA0/usr/htdocs/] applying pattern '^print/162-project-engineer-\357\277\275-gas-processing-and-export/$' to uri 'print/162-project-e
ngineer-О©Ґ-gas-processing-and-export/'
127.0.0.1 - - [08/Apr/2007:09:39:47 +1100] [localhost/sid#81237f0][rid#82f8050/initial] (2) [per-dir /u10/v/vA0/usr/htdocs/] rewrite print/162-project-engineer-О©Ґ-gas-processing-and-export/ -> /print/162-project-engineer---gas-processing-and-export/
127.0.0.1 - - [08/Apr/2007:09:39:47 +1100] [localhost/sid#81237f0][rid#82f8050/initial] (2) [per-dir /u10/v/vA0/usr/htdocs/] explicitly forcing redirect with http://localhost/print/162-project-engineer---gas-processing-and-export/
127.0.0.1 - - [08/Apr/2007:09:39:47 +1100] [localhost/sid#81237f0][rid#82f8050/initial] (2) [per-dir /u10/v/vA0/usr/htdocs/] trying to replace prefix /u10/v/vA0/usr/htdocs/ with /
127.0.0.1 - - [08/Apr/2007:09:39:47 +1100] [localhost/sid#81237f0][rid#82f8050/initial] (1) [per-dir /u10/v/vA0/usr/htdocs/] redirect to http://localhost/print/162-project-engineer---gas-processing-and-export/ [REDIRECT/301]

After last redirect to http://localhost/print/162-project-engineer---gas-processing-and-export/

I cannot access print.php (error log from apache):
[Sun Apr 08 09:39:28 2007] [debug] mod_rewrite.c(1788): [client 127.0.0.1] mod_rewrite's internal redirect status: 0/10.
[client 127.0.0.1] script '/u10/v/vA0/usr/htdocs/print.php' not found or unable to stat
[Sun Apr 08 09:39:28 2007] [error] [client 127.0.0.1] File does not exist: /u10/v/vA0/usr/htdocs/errors
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question