Forum Moderators: phranque

Message Too Old, No Replies

Mod_Rewrite

Got a problem, need advice:

         

internetheaven

6:50 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My URL's look like this:

[example...]

so after some reading I came up with this:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule file/(\.*)/(\.*)/$ /directory/file\.php?$1=$2

for some reason it wouldn't work, I just got internal server errors showing. Then a friend of mine who runs servers said I needed to write Dynamic Mirroring mod_rewrite for what I wanted to do but as far as I can tell, that means writing code for every single page of my site - I have over 300,000 pages so that is not really an option.

What I want is for the information that is currently at:

[example...]

to show up in a browser window (at a crawler/bot request) when you type in:

[example...]

is this impossible?

jdMorgan

7:59 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Rewrite http://www.example/directory1/file/actual-page-name/ to http://www.example/directory1/file.php?id=actual+page+name :

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^file/([^/]+)/([^/]+)/$ /directory1/$1.php?id=$2 [L]

This code assumes that it will be placed in the subdirectory named "/directory1" as shown in your example above.

Jim

internetheaven

8:44 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't seem to get that to work. I placed:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^file/([^/]+)/([^/]+)/$ /directory1/$1.php?id=$2 [L]

in the .htaccess file of /directory1/

but when I enter

[example...]

into the browser it just comes up with the 'page doesn't exist' page.

gergoe

10:26 pm on Jun 22, 2004 (gmt 0)

10+ Year Member



Try

Options +FollowSymLinks
RewriteEngine on
RewriteBase /directory1
RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?id=$2 [L]

Please note that this will not take care of the translation of the hypens to plus signs, that's you need to handle it from your php script (a lot easier than with Apache)

internetheaven

4:32 pm on Jun 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Any tips on how to get my php to do this?

Thanks for all the help so far.

gergoe

6:08 pm on Jun 28, 2004 (gmt 0)

10+ Year Member



See strtr() [php.net] in the PHP manual.