Forum Moderators: coopster & phranque

Message Too Old, No Replies

dynamic to static urls using mod_rewrite

Trying to convert dynamic url to static

         

garyoc

8:27 pm on Jan 16, 2002 (gmt 0)



I'm a non-programmer trying to figure out how mod_rewrite works. Have looked over several posts here, but to no avail. Set up the following as a test:

mydomain.com/rewrite_test/index.php

This page has a link on it that goes to

mydomain.com/rewrite_test/details/index.php?SEL=test1

Where SEL is an include file that is loaded out of

mydomain.com/rewrite_test/includes

I placed the .htaccess file in the /rewrite_test/ directory.

this file currently reads:
RewriteEngine on
RewriteBase /rewrite_test/
RewriteRule ^details/(.*)/(.*)/$ /index.php?$1=$2 [T=application/x-httpd-php,L]

This is like the tenth time I've rewritten the .htaccess file and nothing seems to be happening. I have server access and the module is properly loaded. (In my earliest attempts I did manage to get an internal server error message, so I know it works when I've got my syntax all screwed up) :)

I want to make the url look like

mydomain.com/rewrite_test/details/test1.php

How do I make this happen?

john316

9:19 pm on Jan 16, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try this

RewriteEngine on

RewriteBase /rewrite_test/details/

RewriteRule ^(.*)details/(.*).php$ $1index.php?SEL=$2

edited out a slash

garyoc

10:01 pm on Jan 16, 2002 (gmt 0)



Thank you for coming to my aid so quickly!

Did as you wrote. Recieved internal server error. Checked error log. Said this:

/.htaccess: RewriteBase takes one argument, the base URL of the per-directory

my .htaccess file reads like this:

RewriteEngine on
RewriteBase /rewrite_test/ /details/
RewriteRule ^(.*)details/(.*).php$ $1index.php?SEL=$2

I edited the .htaccess file to read like this:
RewriteEngine on
RewriteBase /rewrite_test/details/
RewriteRule ^(.*)details/(.*).php$ $1index.php?SEL=$2

Now I don't get the internal server error message, but it also doesn't do anything either.

garyoc

10:14 pm on Jan 16, 2002 (gmt 0)



Edited out the slash. No more error message, but doesn't do anything with the url either.

gethan

9:12 am on Jan 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Gary, I missed this one first time round. Did you get it fixed?
RewriteEngine on
RewriteBase /rewrite_test/
RewriteRule (.*)details/(.*).php$ /index.php?SEL=$2 [T=application/x-httpd-php,L]

Will take a url of
mydomain.com/rewrite_test/details/test1.php

and return the output from

mydomain.com/index.php?SEL=test1

(Hope theres no bugs - didn't test it)

Hudzon

5:07 am on Mar 27, 2002 (gmt 0)



could you give me an example for one with more perameters like this one.

[mydomain...]

so it would be

[mydomain...]

or something like that ???

gethan

7:51 pm on Mar 27, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Hudzon,
Welcome to WebmasterWorld, the example you give could be written as:

[perl]
[mydomain...]
from requests for
[mydomain...]

in .htaccess
RewriteEngine on
RewriteBase /cgi-bin/forum/
RewriteRule (.*)/(.*)/(.*)/(.*)\.htm$ /cgi-bin/forum.cgi?$1=$2;$3=$4
[/perl]

Basically each of the $n variables gets the value of the corresponding bracketed section in your rule.

Don't put this on a live server without testing it first ;)

Gethan

Hudzon

8:36 pm on Mar 27, 2002 (gmt 0)



Thanks gethan, it's starting to work but not all the way yet.

I have:
RewriteEngine on
RewriteBase /cgi-bin/forum/
RewriteRule (.*)/(.*)/(.*)/(.*)\.htm$ /cgi-bin/forum.cgi?$1=$2;$3=$4

But when I enter:
[mydomain...]
it olny goes to:
[mydomain...]

mark_roach

8:42 pm on Mar 27, 2002 (gmt 0)

10+ Year Member



Hudzon are you missing

[T=application/x-httpd-cgi]

off the end of the RewriteRule statement ?

Hudzon

10:12 pm on Mar 27, 2002 (gmt 0)



Changing

to

RewriteRule (.*)/(.*)/(.*)/(.*)\.htm$ /cgi-bin/forum.cgi?$1=$2;$3=$4 [T=application/x-httpd-cgi]

did not make a difference :(

Let me thry to be more accurate.

http:www.mydomain.com/cgi-bin/forum.cgi?act=SF;f=1 will open a fourm topic.

I want to have a http:www.mydomain.com/cgi-bin/forum/act/SF/f/1.htm

or some similar format that is search engine frienly open the same file.

I am trying to work on getting an Ikonboard dbd based forum to be spider friendly.

gethan

10:34 pm on Mar 27, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm just wondering if cgi-bin is set to be a special case?

Also from a spider point of view moving the location from cgi-bin is a good idea. Try out...

RewriteEngine on
RewriteBase /forum/
RewriteRule (.*)/(.*)/(.*)/(.*)\.htm$ /cgi-bin/forum.cgi?$1=$2;$3=$4 [T=application/x-httpd-cgi]

(Cheers Mark - the cgi bit should be there)

The above should work - but it is off the top of my head - eg. not tested.

Good luck.

Crazy_Fool

1:43 am on Mar 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok, first time i'm trying this and i've got a couple of queries about it. i don't have my own code so i'm going to use code posted from other messages here.

is the following code sufficient for a complete .htaccess file or is there something else needed?


RewriteEngine on
RewriteBase /forum/
RewriteRule (.*)/(.*)/(.*)/(.*)\.htm$ /cgi-bin/forum.cgi?$1=$2;$3=$4 [T=application/x-httpd-cgi]

do i just put this code in the root of the website (same place as index.html) or in the /forum/ directory or somewhere else?

when the above code is saved in the website root directory as .htaccess, it intercepts all calls to www.domain.com. is that what it is intended to do?

the sooner i get my head around this stuff the happier i'll be.