Solved

help with rewrite rules

Posted on 2007-04-03
19
197 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now