Forum Moderators: phranque

Message Too Old, No Replies

I want to shorten my url. I need an example of Mod_Rewrite rules

I need an example of Mod_Rewrite rule

         

fixitcomputers

12:52 pm on Mar 15, 2006 (gmt 0)

10+ Year Member



I have currently installed metadot on my linux server and I would like to shorten the url

Currently this is an example of what the homepage appears like

http://www.example.com.au/metadot/index.pl

Is there anyway to change it to look like this

http://www.example.com.au

I need an example of what a rewrite rule would look like for the example above as I am having trouble understanding all the Mod_Rewrite rules, A simple example might help me grasp the understanding

This link represents the Contact Us link
http://www.example.com.au/metadot/index.pl?id=1861&isa=Category&op=show

How would I change this to look like?

http://www.example.com.au/contact

Thanks in Advanced, Russell

barns101

2:21 pm on Mar 15, 2006 (gmt 0)

10+ Year Member



I'm just starting to use mod_rewrite so can't answer your question directly, but I found the following tutorial very useful and it will hopefully either answer your query or point you in the right direction ;)

[yourhtmlsource.com...]

jdMorgan

1:07 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be careful with that tutorial, there are some errors in the code.

(Note that WebmasterWorld does not allow the posting of non-authoritative site URLs. The link above is sufficiently useful as to be permitted. However, please be aware that this is an exception.)

Try a search on WebmasterWorld for "RewriteRule static URL dynamic" and similar to turn up dozens of actual implmentations.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

fixitcomputers

3:12 am on Mar 16, 2006 (gmt 0)

10+ Year Member



I am new to this, so to my understanding from reading the below article posted below, is that I can not create a user friendly url to be displayed in the browser

http://www.example.com.au/metadot/index.pl

Is there anyway to change it to look like this

http://www.example.com.au

is this possible or not, I'm getting confused. I read articles to say it is possible, then I read the article below that says it's not possible

Beginning Mod Rewrite

[webmasterworld.com...]

What you Cannot Do:
You cannot use mod_rewrite to change the address displayed in the browser... including to a more 'friendly' URL - The location displayed must either be requested or redirected to. The location does not need to contain any information, but must exist in a request.

Thankyou, Russell

jdMorgan

4:20 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, the point is that mod_rewrite does not change the URL that your visitors and search engines 'see' on a page. What it does do is either redirect or rewrite that URL when it is requested from your server -- when a visitor clicks the link or a spider follows it.

So, the procedure is: Change your site so that its pages show 'short' or 'search-engine-friendly' URLs. Then use mod_rewrite to 'map' those URLs back to the correct files when someone uses a short URL to make a request to your server.

The most confusing point is that of direction -- what is rewritten from and what is rewritten to. Mod_rewrite changes the filename associated with a URL. And it does so after that URL request arrives at your server, and before any content-handlers or scripts are invoked. In other words, it is a front-end process in handling a request, and not any kind of back-end page-content/output modifier.

The new short URL must contain sufficient information to re-construct the unique 'real' filename. Much planning should go into this, since a well-planned solution will require only one RewriteRule (or a few), while a poorly-planned solution can require one rule for each URL you want to replace. Generally, the more organized the existing URLs are, the easier it is to replace them.

Jim