We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,473 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Htaccess | auto change url

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 .

3
Contributors
5
Replies
15 Hours
Discussion Span
1 Year Ago
Last Updated
6
Views
haimz
Light Poster
30 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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?

diafol
Keep Smiling
Moderator
10,675 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57

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

haimz
Light Poster
30 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

vibhaJ
Posting Shark
958 posts since Apr 2010
Reputation Points: 161
Solved Threads: 190
Skill Endorsements: 3

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
diafol
Keep Smiling
Moderator
10,675 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57

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 .

haimz
Light Poster
30 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0710 seconds using 2.67MB