Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirrect

dynamic redirrection

         

WhosAWhata

10:55 pm on Jan 20, 2004 (gmt 0)

10+ Year Member


i've heard .htaccess is pretty powerful
is the a way to redirect the following?
http://www.something.com/dir/[b]file[/b].htm
TO
http://www.something.com/dir/index.php?p=[b]file[/b]

ex
they put poetry.htm
it will go to index.php?p=poetry
or apple.htm
would be redirrected to index.php?p=apple

THANKS

[1][[b]edited by[/b]: WhosAWhata at 1:40 am (utc) on Jan. 21, 2004][/1]

jdMorgan

12:18 am on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



WhosAWhata,

Yes.

Start here: Introduction to mod_rewrite [webmasterworld.com]

Jim

WhosAWhata

1:36 am on Jan 21, 2004 (gmt 0)

10+ Year Member



i tried to trudge through that, but it didn't quite make sense
i've never used a .htaccess file (except ones that were generated with php files on my server)

can you give me an example of how to dirrect like i described please?

operafan

3:40 am on Jan 21, 2004 (gmt 0)

10+ Year Member



I think what you've requested is a function of converting your static pages to dynamic?
If that's the case you can try this :

RewriteEngine On
RewriteRule ^file[0-9]\.php$ /index.php?p=file$1 [L]

The above mentioned is only for site with single id's since your's b I presume represents the ID than you'll have to tweak the Rewriterule a bit. That's just a rough idea of how it should be done. I don't know enough to give you the correct syntax. But do a search on WebmasterWorld on that, I've seen it requested a thousand times on this board, so that poor Jim doesnt have to repeat it all over again.. cheers.

WhosAWhata

4:00 am on Jan 21, 2004 (gmt 0)

10+ Year Member



actually what i ment is that if the write file.htm it goes to index.php?p=file
if they write something.htm
it goes to index.php?p=something

operafan

6:16 am on Jan 21, 2004 (gmt 0)

10+ Year Member



Whoa, then I suggest you use/learn Regular Expression to represent all the letters that your surfer might type..
As you've said - something.htm to be redirected to php?p=something.
As I've posted earlier - the id(0-9) , (0-9) is a regular expression to represent any id(matching from 0 - 9) & then modrewrite will direct the surfer to the dynamic string
So in your case which is letters instead of numbers you'll have to use the regular expression as such example - ([a-z]*)which on represent 1 letter in a list of letters.
As Jim has helped me out before with id's ranging from 1 - 100 , I can use [(0-9){1,3}] {1,3} to represent the 3 digits, I dont know if this rule applies to letters though.

Yes, and what you want to do can be done by .htaccess/modrewrite rules.

Being still newbie in modrewrite I can only tell you that much..

WhosAWhata

12:58 am on Jan 22, 2004 (gmt 0)

10+ Year Member



ok thanks