Home

Forums

Web development

 

 

 

 
     
 
dna88 Web development and Technology Forum
 
Profile   Register   Memberlist   Usergroups   FAQ   Search  Log in
What is mod rewrite? How to use mod rewrite? Why use?

 
Post new topic   Reply to topic    dna88 Forum Index -> Web scripting language Discussion Forum
Author Message
emm
Power User
Power User


Joined: 13 Jul 2004
Posts: 310

Post Post subject: What is mod rewrite? How to use mod rewrite? Why use? Reply with quote

I have heard that mod rewrite can do wonderful things for a website. Mod rewrite is specially helpful for search engine optimization too. Can anyone please explain to me what is mod rewrite and how to use modrewrite usefully?
_________________
“You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh
Thu Aug 26, 04 4:14 am
Back to top
emm View user's profile Send private message
redsky
Beginner User
Beginner User


Joined: 01 Aug 2004
Posts: 26

Post Post subject: Reply with quote

I see this word on apache http.conf. Are these word same for same work?
Thu Aug 26, 04 7:02 am
Back to top
redsky View user's profile Send private message
quantum
Site Admin
Site Admin


Joined: 07 Mar 2004
Posts: 1048
Location: Dhaka, Bangladesh

Post Post subject: Mod rewrite for search engine /google friendly page Reply with quote

Well, mod rewrite is to change file names and make it look more search engine friendly. For instance, this forum uses complex url when you go to a specific forum or view a topic. Look at the address bar. It is something like [http://www.quantumcloud.com/forum/viewtopic.php?t=367] right? This is not very search engine friendly. Because the difference between one topic page and another is only a variable! On the other hand if the url was something like [http://www.quantumcloud.com/forum/topic-2004.htm] and [http://www.quantumcloud.com/forum/topic-2005.htm] etc then it would be much more search engine friendly and google would remember it for a longer time. Changing the whole phpbb code to generate url like that is impossible. But with the help of modrewrite you can do it! That's the main benefit of mod rewrite.

Mod rewrite only works on apache based server and it has to be turned on from http.conf as redsky says.

Example of how to write mod rewrite:

Code:
RewriteEngine On
RewriteRule ^index(.*).php$ index.php?foo=$1 [L,NC]


RewriteEngine On Just tells apache you will be "masking" some filenames.

RewriteRule ^index(.*).php$ index.php?foo=$1 [L,NC]
Tells apache you are rewriting anything that is in the format indexbar.php to index.php?foo=bar, and that it is all being done on the local server.

Save this file as .htaccess. If you are in windows, save it as htaccess.txt then upload it, and use your ftp client's rename function to rename it to .htaccess.

So now whenever you want to pass variable "foo" with value "bar" within your page simply link to indexfoo.php.

Other forms can be created, allowing multiple variables such as:

Code:
RewriteRule ^index_(.*)_(.*)_(.*).php$ index.php?foo=$1&foo2=$2&foo3=$3 [L,NC]


That just tells apache that index_bar_bar2_bar3.php really is index.php?foo=bar&foo2=bar2&foo3=bar3.

The main functions that you can use with mod rewrite are:

RewriteEngine
RewriteOptions
RewriteLog
RewriteLogLevel
RewriteLock
RewriteMap
RewriteBase
RewriteCond
RewriteRule

You can read details on them here:
[http://www.apacheref.com/ref/mod_rewrite.html]

Mod rewrite home page is of course, [http://www.modrewrite.com/] Gentle smile
_________________

Dust fills my eyes / Clouds roll by / and I roll with them / Centuries cry / Orders fly / and I fall again
Afford best design, implement best solution. Outsource your web design.
Fri Aug 27, 04 12:07 am
Back to top
quantum View user's profile Send private message Visit poster's website AIM Address
quantum
Site Admin
Site Admin


Joined: 07 Mar 2004
Posts: 1048
Location: Dhaka, Bangladesh

Post Post subject: Reply with quote

There might be other ways. But to the best of my knowledge, .htaccess is the only way to do modrewrite in an apache server.
_________________

Dust fills my eyes / Clouds roll by / and I roll with them / Centuries cry / Orders fly / and I fall again
Afford best design, implement best solution. Outsource your web design.


Last edited by quantum on Sun Aug 29, 04 8:06 am; edited 2 times in total
Sun Aug 29, 04 5:29 am
Back to top
quantum View user's profile Send private message Visit poster's website AIM Address
redsky
Beginner User
Beginner User


Joined: 01 Aug 2004
Posts: 26

Post Post subject: Reply with quote

wel, now i understand. Thanks
Sun Aug 29, 04 7:15 am
Back to top
redsky View user's profile Send private message
emm
Power User
Power User


Joined: 13 Jul 2004
Posts: 310

Post Post subject: Mod rewrite complex Reply with quote

The syntax looks very complex. But it can do some useful things. I should try to learn to use it. It will be helpful.
_________________
“You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh
Mon Aug 30, 04 12:58 am
Back to top
emm View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    dna88 Forum Index -> Web scripting language Discussion Forum All times are GMT - 7 Hours
Page 1 of 1

 

Partners and Resources

Bangladesh hosting company

Bangladesh web design

Driven by phpBB © phpBB Group