hello evryone,
i'm changin the url by

RewriteEngine on
RewriteRule ^forum-(.*).html$ ./forum.php?id=$1

now if the url is forum.php?id=231, how can i auto change the url to forum-231.html
thanks,
haim .

Recommended Answers

All 5 Replies

Member Avatar for diafol
RewriteRule ^forum-(.*).html$ forum.php?id=$1 [L,QSA]

That work?

Mind you POSIX gets me every time. Is the '-' valid? Does it have to be escaped?

i thought the same, but thats works for me, and the code was just an exmplame,
i will check yours,
thanks :)

thats not works :(
its my code:

RewriteEngine On
RewriteRule ^forum-(.*).html$ index.php?showforum=$1 [L,QSA]

when im going to index.php?showforum=2 its not redirecting me to forum-2.html,
when im going to forum-1.html i see the content of index.php?showforum=1

index.php?showforum=2 won't redirect you at forum-2.html.
You have to make your href and redirection such that forum-2.html will comes in url.

Member Avatar for diafol

POSIX gives me a nosebleed as I say, so I use - http://martinmelin.se/rewrite-rule-tester/

This is what my idea gave (says it works):

when im going to index.php?showforum=2 its not redirecting me to forum-2.html, when im going to forum-1.html i see the content of index.php?showforum=1

No this is expected. The whole point is that your urls (the ones you use in your links) are in the 'short' format. This is what everybody sees. The 'long' url should still work, after all this is what the server sees with the short version (rewrite).

So when you produce dynamic urls:

Don't create long ones, create short ones:

<a href="forum-<?php echo $id;?>.html">...</a>


instead of

<a href="index.php?showforum=<?php echo $id;?>">...</a>

I NEED CODE thats redirects automaticaly to forum-1.html, if the url is index.php?showforum=1, i cant change the link because is abig system and he got alot of links .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.