Forum Moderators: phranque

Message Too Old, No Replies

Rewrite help

Rewrite help

         

James302415

2:46 pm on Jun 29, 2005 (gmt 0)

10+ Year Member



Hi,

I'm trying to set up search engine friendly urls for my dynamic sites that run on php. So far I have tried something really simple by changing one file to another using rewrite. I then tried to rewrite a url that looked something like this

www.mydomain.com/testfolder/test/1

to become

www.mydomain.com/testfolder/test.php?f=1

I used a .htaccess file which is in the testfolder. Here is the code i have tried to use but it doesn't work.

RewriteEngine On
RewriteRule ^test/([0-9]*)$ /testfolder/test.php?f=$1 [L]

I have nothing else in the .htaccess file.

Any help would be appreciated! :-)

ckarg

7:39 pm on Jun 29, 2005 (gmt 0)

10+ Year Member



When experimenting mod_rewrite, two key directives are:

RewriteLog file-path
RewriteLogLevel Level

Depending on the LogLevel, you'll see which conditions have matched, and how urls are transformed.

The ^ caret at the beginning of the left expression signifies "start of string", but your full url doesn't start with test....

You might want to try:
RewriteRule ^testfolder/test/([0-9]*)$ /testfolder/test.php?f=$1 [L]

You might also want to browse the online docs:
httpd.apache.org/docs-2.0/mod/mod_rewrite.html#rewriterule

James302415

8:38 am on Jun 30, 2005 (gmt 0)

10+ Year Member



Thanks for the help but still getting a 404. Maybe i'm setting my sights too high at first. What if I just wanted to turn this
www.mysite.com/test/news into this www.mysite.com/test/news.php

RewriteEngine On
RewriteBase /testfolder
RewriteRule ^/news$ /news.php [L]

I'm using shared hosting so I think I need to use the RewriteBase, is this right? I have tried this code but still getting 404s.

Any help again would be appreciated. Thanks

jdMorgan

11:39 pm on Jul 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should not need to use RewriteBase, unless you are using an Alias for your testing directory in httpd.conf.
RewriteLog and related directives are not available in .htaccess.
URLs seen by RewriteRule are localized to the directory in which the .htaccess file with that rewriterule resides.
Your server may append a trailing slash to requests with no filetype.
So,

RewriteEngine On
RewriteRule ^news/?$ /news.php [L]

You may also need to add the directive

Options +FollowSymLinks

ahead of the code above; See your server error log after testing, as it may contain useful information.

Jim