1,105,578 Community Members

Htaccess | auto change url

Member Avatar
haimz
Light Poster
30 posts since Jun 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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 .

Member Avatar
diafol
Where are my eyes?
12,983 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
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?

Member Avatar
haimz
Light Poster
30 posts since Jun 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
vibhaJ
Posting Shark
960 posts since Apr 2010
Reputation Points: 126 [?]
Q&As Helped to Solve: 190 [?]
Skill Endorsements: 3 [?]
 
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.

Member Avatar
diafol
Where are my eyes?
12,983 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
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
Member Avatar
haimz
Light Poster
30 posts since Jun 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: