Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule help

         

niza

2:29 pm on Oct 9, 2007 (gmt 0)

10+ Year Member



Hi,

I am trying to make friendly urls for my website.

Here's what I want:
www.mydomain.com/display_ad.php?id=3 to become
www.mydomain.com/display_ad_3.html

I read some tutorials on modyifing the .htaccess file and here's what I got so far:

AddHandler server-parsed .htm
AddHandler server-parsed .htm

RewriteEngine On
RewriteBase /

RewriteRule ^display_ad_([0-9]+)\.html$ /display_ad.php?id=$1 [L]

And it's not working. Anyone knows where the mistake is?

Thanks

jdMorgan

2:36 pm on Oct 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code looks OK, aside from the repeated AddHandler at the top.

How, specifically, does this 'not work'?

How did you test?
What were the results?
How did these results differ from what you expected?
Did you flsuh your browser cache before testing, and after any change to the code?

Jim

niza

2:51 pm on Oct 9, 2007 (gmt 0)

10+ Year Member



I did flushed the browser and I tested it in 2 ways:

1. I just typed the url in the browser: www.mydomain.com/display_ad_3.html
2. I have an index page where the ads are displayed and I clicked the link in there. The address in the browsers changes to www.mydomain.com/display_ad_3.html

In both situations I get the following error:

Error 404: NOT FOUND!
Your browser cannot find the document corresponding to the URL you typed in

And yes, there is an ad where id=3. If I type www.mydomain.com/display_ad.php?id=3 I get the page with no problems.

jdMorgan

2:53 pm on Oct 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What do you see in your server error log?

Jim

niza

3:29 pm on Oct 9, 2007 (gmt 0)

10+ Year Member



Hey Jim.

My host is 1and1.com and unfortunatelly they don't allow access to the error logs only access, ftp and mail logs (which I just checked and everything looks fine).

Is there another way to troubleshoot this?

Thanks

niza

7:50 am on Oct 10, 2007 (gmt 0)

10+ Year Member



I've also made a very simple rewrite.

I have 2 pages: alice.html and bob.html

Here's the rewrite:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /

RewriteRule ^alice.html$ bob.html

If I go the alice.html I should get the bob.html page right? When I access the alice.html file I get the error:

Error 404: NOT FOUND!
Your browser cannot find the document corresponding to the URL you typed in.

<snip>

I read somewhere that I should make phpinfo() file to see if mod_rewrite is enabled on my server. Here's the file
http://s125410096.example.com/rewrite/info.php
but I don't see anythng related to mod_rewrite. Does that mean it's disabled?

This is very frustrating.

[edited by: jdMorgan at 1:33 pm (utc) on Oct. 10, 2007]
[edit reason] No URLs, please. See TOS. [/edit]

jdMorgan

1:40 pm on Oct 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can test to see if mod_rewrite is available and working by doing a simple external redirect. Something like:

Options +FollowSymLinks +Indexes
RewriteEngine on
#
RewriteRule ^alice\.html$ http://www.google.com/ [R=302,L]

If that works, but your internal rewrites don't work, then that indicates that you need to set up a RewriteBase due to the current URL-to-filename mapping configuration of your server. Without access to error logs, there's no good way to see what the value of RewriteBase needs to be, though. I suppose you could ask your host and see if they will tell you.

Using mod_rewrite on a server with no access to error logs is frustrating and may cost you hours of extra time every time you add mod_rewrite code that isn't absolutely correct.

Jim

g1smd

11:13 pm on Oct 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Err. I think 1&1 don't allow URL rewrites on some of their more basic packages. I remember having big problems with rewrites and redirects a year ago on a site hosted with them. I can't remember what was done to fix it, but I think it might have involved changing host.