473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

URL Rewriting

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

Nov 12 '05 #1
7 2068
Ed
go@thescriptsmailer.com wrote:
Can someone please tell me what URL rewriting is? I don't understand . . . a client is asking me to rewrite his URLs.


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 =----
Nov 22 '05 #2
go@thescriptsmailer.com wrote:
Can someone please tell me what URL rewriting is? I don't understand . . . a client is asking me to rewrite his URLs.


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.
Nov 22 '05 #3
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/

Nov 22 '05 #4
go@thescriptsmailer.com wrote:
a client is asking me to rewrite his URLs.


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.
Nov 22 '05 #5
Bill Karwin <bi**@karwin.com> wrote:
for a couple of minutes but I didn't see a concise alternative proposed
for PHP applications to do this in script code.


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
--
Nov 22 '05 #6
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" <pa******@zoominternet.net> wrote in message
news:11************@spool6-east.superfeed.net...
go@thescriptsmailer.com wrote:
Can someone please tell me what URL rewriting is? I don't understand . .
. a client is asking me to rewrite his URLs.


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
=----

Dec 1 '05 #7
"feed_sheep" wrote:
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?


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/

Dec 1 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jon Maz | last post by:
Hi All, I am experimenting with URL Rewriting using the techniques outlined by Scott Mitchell in his article "URL Rewriting in ASP.NET"...
3
by: Jamie Jackson | last post by:
I'm rewriting all links' onclick events, but I'm having a problem. The onclick event that I'm inserting works correctly in Opera, but not in FF or IE. I'm retroactively adding the statement...
2
by: Jon Maz | last post by:
Hi All, I've been looking into options for URL Rewriting in .net, and to be honest, I haven't seen anything that's easier than the old Classic Asp solution with an ISAPI filter redirecting to an...
3
by: Michael Appelmans | last post by:
I'm trying to use a rule based URL rewrite application which uses HttpApplication.RewritePath. I keep getting "rsource not found" error in application when running on shared web host although the...
2
by: R-D-C | last post by:
Can these two functions coexist? We have a web site where the querystrings are removed using URL Rewriting. Instead the page appears to be a html page with a long name (containing what would be...
0
by: Lee | last post by:
Hi all ;) Preamble -------- I'm using URL rewriting to enforce a frames policy (yeah, I know frames are 'bad' :) - i.e. if a request comes in for a page which should be nested within a...
3
by: Greg Collins [Microsoft MVP] | last post by:
I have done a bit of research of Url Rewriting, but as yet have been unsuccessful at getting it to work well, and there are issues around what file types are supported and how much code you want to...
9
by: Frankie | last post by:
I understand that with URL rewriting we can have a request come in for, say Page1.aspx, and rewrite it so that PageA.aspx gets served up to the user. My question (assuming the above is correct):...
2
by: Seth Williams | last post by:
The first scenario is that I want to create one website for a particular industry - let's say for Farm Machinery so I have a shared hosting site called myFarmMachinery.com But I want to sell...
1
Shinobi
by: Shinobi | last post by:
I am using ASP.net(c#) for my project. In my my project 2 pages are using URL rewriting method by referring this article URL Rewriting using Intelligencia UrlRewriter Example 1 - Blog Day...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.