Connecting Tech Pros Worldwide Help | Site Map

URL Rewriting

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 12:15 AM
go@thescriptsmailer.com
Guest
 
Posts: n/a
Default URL Rewriting

Can someone please tell me what URL rewriting is? I don't understand . . . a client is asking me to rewrite his URLs.


  #2  
Old November 21st, 2005, 11:05 PM
Ed
Guest
 
Posts: n/a
Default Re: URL Rewriting

go@thescriptsmailer.com wrote:[color=blue]
> Can someone please tell me what URL rewriting is? I don't understand . . . a client is asking me to rewrite his URLs.
>[/color]

Hi there,

What your client is probably referring to is Apache's mod_rewrite
module. It is often used to rewrite 'static' URLs to dynamic ones,
which has several advantages; URLs are easier to remember, it makes
pages more search engine friendly, and I personally like the ability to
hide URL strings for security reasons.

Rewrite rules are generally written in an .htaccess file, see an example
below:

RewriteEngine on
RewriteRule ^fake_directory/?$ index.php?id=2 [NC]

Though the address bar in the browser will show
http://mydomain.com/fake_directory/, you really are serving
http://mydomain.com/index.php?id=2.

Something more dynamic (you can use regular expressions):

RewriteRule ^fake_directory/([a-zA-Z0-9]+)/?$ index.php?id=2&string=$1 [NC]

The above will rewrite
http://mydomain.com/fake_directory/{custom_string}/ to
http://mydomain.com/index.php?id=2&string={custom_string}

I am sure someone more knowledgeable will be able to provide you with a
better explanation - I have only just started learning it. You could
also search the web for 'mod_rewrite', there are quite a few good
tutorials around. I found
http://www.workingwith.me.uk/article...g/mod_rewrite/ quite
helpful. I must warn you - mod_rewrite is addictive ;-)

Good luck,

Ed


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
  #3  
Old November 21st, 2005, 11:05 PM
Bill Karwin
Guest
 
Posts: n/a
Default Re: URL Rewriting

go@thescriptsmailer.com wrote:[color=blue]
> Can someone please tell me what URL rewriting is? I don't understand . . . a client is asking me to rewrite his URLs.[/color]

Basically, it's when you send a request URL to a web server, and the
server maps the URL to some other request, to give you a page (or other
type of resource) that is at a different location.

This is useful, for example, when a page changes location, but you want
people to be able to find it at the old location, in case they have
bookmarks, or access it from a link on another site or search engine.

Also, you might want to allow people to use a simple URL, even if your
PHP application requires a number of complex and ugly-looking parameters.

One might also use this method to redirect web surfers to mirrored
copies of files on other servers.

The means to implement URL rewriting are various. It seems like most
often people use Apache's mod_redirect or mod_rewrite modules to do it.
There are numerous tutorials on these modules available, even from the
Apache.org site.

But other people say that using mod_rewrite for any significant number
of pages gets very complex and laborious to maintain. I searched google
for a couple of minutes but I didn't see a concise alternative proposed
for PHP applications to do this in script code.

Regards,
Bill K.
  #4  
Old November 21st, 2005, 11:05 PM
Hemant
Guest
 
Posts: n/a
Default Re: URL Rewriting

More good option to use the url rewriting is from search engine point
of view too.

Lets see the website has the category page that lists the webpage as
www.yourdomain.com/category.php?id=1 likewise many more lets say upto
www.yourdomain.com/category.php?id=100
Now search engine considers only one page
www.yourdomain.com/category.php as granted for submission but you can
use the url rewrite power using .htaccess file so that each category id
gets replaced with the catgory name lets say like
www.yourdomain.com/category/computer/ or
www.yourdomain.com/category/bags/ or
www.yourdomain.com/category/tshirts/ like that.

Regards,
http://binaryelectron.tripod.com/

  #5  
Old November 21st, 2005, 11:05 PM
Bill Karwin
Guest
 
Posts: n/a
Default Re: URL Rewriting

go@thescriptsmailer.com wrote:[color=blue]
> a client is asking me to rewrite his URLs.[/color]

One more comment: if the task isn't clear, you need to ask the client
to be more specific.

Rewrite which URLs? From what original URL to what replacement URL?
For what purpose do the URLs need to be rewritten -- have pages moved
location, or is it desired to have more human-readable URLs that
correspond to request parameters (as in Hemant's reply above), or some
other goal?

But I understand if you want to know more about URL rewriting before you
go ask for clarification. A number of useful articles come up if you go
to www.google.com and search for "url rewriting php tutorial".

Regards,
Bill K.
  #6  
Old November 21st, 2005, 11:05 PM
Ja NE
Guest
 
Posts: n/a
Default Re: URL Rewriting

Bill Karwin <bill@karwin.com> wrote:
[color=blue]
> for a couple of minutes but I didn't see a concise alternative proposed
> for PHP applications to do this in script code.
>[/color]

I'm not an expert, but when I wanted to give my users short uri instead
of domain.name.tld/index.php?pages=user&id=007 I made:

$person = $_GET['nick'];
if(isset($person)) {
$query = "SELECT id FROM table WHERE nick='$person'";
$result = mysql_query ($query) or die ("$query");
list($id) = mysql_fetch_array($result);
header("Location: index.php?pages=user&id=$id");
}

so users personal uri is like domain.name.tld/?nick=bond

if I need or want, I can change new location to anything more complex
(nothing cames to my mind right now)

--
Ja NE
http://fotozine.org/?omen=janimir
--
  #7  
Old December 1st, 2005, 08:05 PM
feed_sheep
Guest
 
Posts: n/a
Default Re: URL Rewriting

I'm confused. I have set the following

RewriteEngine on
RewriteRule ^alumni/?$ index.php?content=alumni

When I type www.site.com/alumni, it loads the index.php?content=alumni
But when I type www.site.com/alumni/ it looks in the real folder on the site
for an index.php (and doesn't find one). Plus, it sets all URLs in the page
to be www.site.com/alumni/whatever.php

What am I doing wrong?

Thanks,

David


"Ed" <paperhat@zoominternet.net> wrote in message
news:1131758972_317@spool6-east.superfeed.net...[color=blue]
> go@thescriptsmailer.com wrote:[color=green]
>> Can someone please tell me what URL rewriting is? I don't understand . .
>> . a client is asking me to rewrite his URLs.
>>[/color]
>
> Hi there,
>
> What your client is probably referring to is Apache's mod_rewrite module.
> It is often used to rewrite 'static' URLs to dynamic ones, which has
> several advantages; URLs are easier to remember, it makes pages more
> search engine friendly, and I personally like the ability to hide URL
> strings for security reasons.
>
> Rewrite rules are generally written in an .htaccess file, see an example
> below:
>
> RewriteEngine on
> RewriteRule ^fake_directory/?$ index.php?id=2 [NC]
>
> Though the address bar in the browser will show
> http://mydomain.com/fake_directory/, you really are serving
> http://mydomain.com/index.php?id=2.
>
> Something more dynamic (you can use regular expressions):
>
> RewriteRule ^fake_directory/([a-zA-Z0-9]+)/?$ index.php?id=2&string=$1
> [NC]
>
> The above will rewrite http://mydomain.com/fake_directory/{custom_string}/
> to http://mydomain.com/index.php?id=2&string={custom_string}
>
> I am sure someone more knowledgeable will be able to provide you with a
> better explanation - I have only just started learning it. You could also
> search the web for 'mod_rewrite', there are quite a few good tutorials
> around. I found
> http://www.workingwith.me.uk/article...g/mod_rewrite/ quite
> helpful. I must warn you - mod_rewrite is addictive ;-)
>
> Good luck,
>
> Ed
>
>
> ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet
> News==----
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
> Newsgroups
> ----= East and West-Coast Server Farms - Total Privacy via Encryption
> =----
>[/color]


  #8  
Old December 1st, 2005, 10:35 PM
Philip Ronan
Guest
 
Posts: n/a
Default Re: URL Rewriting

"feed_sheep" wrote:
[color=blue]
> I'm confused. I have set the following
>
> RewriteEngine on
> RewriteRule ^alumni/?$ index.php?content=alumni
>
> When I type www.site.com/alumni, it loads the index.php?content=alumni
> But when I type www.site.com/alumni/ it looks in the real folder on the site
> for an index.php (and doesn't find one). Plus, it sets all URLs in the page
> to be www.site.com/alumni/whatever.php
>
> What am I doing wrong?[/color]

I *may* be mistaken, and I often am when it comes to RewriteRules, but I
think what is happening is that your request for "alumni/" is being
implicitly converted into a request for "alumni/index.php" by a
DirectoryIndex rule somewhere else.

So perhaps if you change your rule to...

RewriteRule ^alumni(/.*)?$ index.php?content=alumni

....then you might have more luck.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.