1.11M Members

Htaccess | auto change url

 
0
 

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 .

 
0
 
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?

 
0
 

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

 
0
 

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.

 
0
 

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):

Capture.PNGwhen 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>
Attachments Capture.PNG 18.49KB
 
0
 

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 .

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: