Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite

starting really simple

         

paradoxos

4:15 am on Jan 30, 2005 (gmt 0)

10+ Year Member



ok. i've just updated my .htaccess page, does it take awhile until it recognizes mod_rewrite rules? I've done a simple one after hours of research. I did:

RewriteEngine On
RewriteRule ^book/([^/\.]+)/?$ book.php?redirectNAME=$1 [L]

to have

www.XXX.com/book.php?redirectNAME=BookName

become

www.XXX.com/book/BookName/

please help I'm totally confused why this doesn't work.

jdMorgan

4:44 am on Jan 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Changes to .htaccess take place immediately. However, you must flush your browser cache (Temporary Internet Files for MS IE on Windows) before testing *any* change to your access-control code.

Do you have access to your server error log file? A common problem is that mod_rewrite requires FollowSymLinks or SymLinksIfOwnerMatch to be enabled before mod_rewrite will function. If you do not have this setting, your code will have no effect, but your server error log will tell you of this exact problem.

Try an even simpler rewrite:


RewriteEngine On
RewriteRule ^test\.html$ /book.php?redirectNAME=Bookname [L]

(Bookname above must be a valid book name, and http://www.yourdomain.com/book.php?redirectNAME=Bookname must be a valid "page.")

Next, Flush your browser cache.

Now type http://www.yourdomain.com/test.html into your browser and click "go".

You should see the output of the page http://www.yourdomain.com/book.php?redirectNAME=Bookname, but the browser address bar should remain unchanged and still show http://www.yourdomain.com/test.html

Jim

paradoxos

4:58 am on Jan 30, 2005 (gmt 0)

10+ Year Member



OK. I did the 'test.html' thing and it worked. It showed the /book.php?redirectNAME=BookName page without any data. (Blank)

SO it seems to work. But I'm still not able to have the redirect work for the /book/BookName/ idea. AM I missing something? I have a blog that uses redirects on the same server just fine as well. Is my htaccess code wrong? I'm totally lost here.

jdMorgan

5:24 am on Jan 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's no need to escape "." within a grouped alternate set -- within square brackets, that is. And it's a good idea to 'root' your substitution URL-path unless you have a reason not to. But neither of these are "fatal" problems, so your code should have worked. Here's the slightly tuned-up code:

RewriteEngine On
RewriteRule ^book/([^/.]+)/?$ /book.php?redirectNAME=$1 [L]

Note that if you have a valid subdirectory named "/book" then this code should be placed there (after removing "book/" from the rewriterule pattern). OR, you might need to enable RewriteOptions inherit in that subdirectory to get this code to work in your root folder -- This depends on your server setup.

Jim

PhraSEOlogy

5:36 am on Jan 30, 2005 (gmt 0)

10+ Year Member



JD,

Some good advice there about doing the test thing. I was having trouble with converting a dynamic site to use mod_rewrite to make "real" URLs. I set up a test html page with all of the possible url combinations of rewrite that I would need and then clicked the links - on at a time - making sure the mod_rewrite code handled that specific situation. After two days of coding I have a fully mod_rewrite enaabled version of the site.

To quote the apache docs - mod_rewrite is voodoo!

Using a series of simple tests makes life a lot easier.