FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Help Needed - URL format





samay
I want to know how to create different format.

eg. for a URL

www.website.com/index.php?user=username

can i convert it to

www.website.com/username

can anyone please help me with this.
samay
I also want to know that can I have dynamic contents with .html extension.

I mean how can I change the .php extension to .html ??
MrBlueSky
samay wrote:
I want to know how to create different format.

eg. for a URL

www.website.com/index.php?user=username

can i convert it to

www.website.com/username

can anyone please help me with this.


Put this in your .htaccess:

Code:


RewriteEngine on
RewriteCond %{QUERY_STRING} ^user=([^=]*)
RewriteRule ^index.php$ %1

MrBlueSky
samay wrote:
I also want to know that can I have dynamic contents with .html extension.

I mean how can I change the .php extension to .html ??


And... add this line to your .htaccess:

Code:

AddType application/x-httpd-php .html


.htaccess is a powerfull thingy Very Happy
samay
Can you please explain what is this and how it works ???

MrBlueSky wrote:
samay wrote:
I want to know how to create different format.

eg. for a URL

www.website.com/index.php?user=username

can i convert it to

www.website.com/username

can anyone please help me with this.


Put this in your .htaccess:

Code:


RewriteEngine on
RewriteCond %{QUERY_STRING} ^user=([^=]*)
RewriteRule ^index.php$ %1

MrBlueSky
samay wrote:
Can you please explain what is this and how it works ???


Difficult to explain, but I'll try.

It uses the apache module mod_rewrite which lets you rewrite URLs based on certain conditions.

Code:

RewriteCond %{QUERY_STRING} ^user=([^=]*)


This is a condition. If this condition is met, the rewrite rule below it will be used. Basically it says something like: if the querystring of the url begins with user= then the condition is met, and put the text after user= up to the next = or the end of the string in a variabele named %1.

Code:

RewriteRule ^index.php$ %1


This is the rewrite. It will be used if the condition above is true, and it means something like: if the URL is index.php replace it with the content of variable %1.

Example:
if someone asks for www.site.com/index.php?user=john, the url is "index.php" (the part which specifies the host is removed) and the query string is "user=john". The query matches the specified pattern and "john" is stored in %1. Since the url matches the pattern of the rewrite rule ("index.php") it is replaced by the content of %1, so the new url is "john". The removed host part is added again, and the result is: www.site.com/john.
Related topics
Help needed from Noobie and other graphic artists.
Wordpess help needed.
Help needed :P
CALLING ALL ACTIONSCRIPTERS, NEED HELP ASAP (IM SERIOUS)
Need help with my Blog sidebar
Form Mail Help Needed
PHP Read File Help needed.
Help needed to make text box and poll script
Big Help needed .
Help needed: Video Compression for MP3 player
Virtual Dub: Help Needed
CSS help needed with list style menubar
help needed with css & javascript
Help needed from a volunteer WEB/player DEVELOPER/programmer
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.