473,804 Members | 3,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2096
Ed
go@thescriptsma iler.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@thescriptsma iler.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@thescriptsma iler.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.co m> 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($perso n)) {
$query = "SELECT id FROM table WHERE nick='$person'" ;
$result = mysql_query ($query) or die ("$query");
list($id) = mysql_fetch_arr ay($result);
header("Locatio n: 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?conte nt=alumni

When I type www.site.com/alumni, it loads the index.php?conte nt=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******@zoomi nternet.net> wrote in message
news:11******** ****@spool6-east.superfeed. net...
go@thescriptsma iler.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?conte nt=alumni

When I type www.site.com/alumni, it loads the index.php?conte nt=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?conte nt=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
8657
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" (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/htm l/urlrewriting.asp). In the article he mentions a problem with postbacks: "If the URLs you are rewriting contain a server-side Web Form and perform postbacks, when the form posts back, the underlying URL will be used". His...
3
3272
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 "return promptBeforeOpening();" FF and IE rewrite it as I would expect them to, but it turns out that that doesn't work (no disclaimer pops up, and the link is not disabled):
2
2603
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 .asp page with responsibility for handling the redirect. I'm now planning to use this solution with my next .net project, and was wondering if anyone else out there has done this already, and what problems (if any) arise. Hopefully the news...
3
2753
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 software runs fine on my localhost. Is it possible that the web hosting service has configured something in the machine.config file to disable URL rewriting? I have been communicating with them but they seem clueless as to the cause. Thanks for...
2
2470
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 in the querystring). I have tried switching on output caching and varying by a parameter and using VaryByCustom but the caching simply does not work. Tested it by adding the time to the bottom of the page and the time updates every time we...
0
2131
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 frameset, the url is rewritten to something of the form 'http://www.blah.com/framesdoc.aspx?lowerFrame=/page.aspx', the 'framesdoc' page then dynamically generates the src attribute for the
3
4745
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 write. While working on a similar, though partially unrelated, issue, I came across a possible alternate method. Before I pursue this method in full, I wanted to get opinions of others as to any unforseen issues I might encounter. The method is...
9
628
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): What does the user see in the browser after URL Rewriting? In the above case, when PageA is rendered to the browser, will the address bar show "PageA.aspx" or would it show "Page1.aspx" - the originally requested URL? Thanks.
2
2354
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 site creation, using database page creation to multiple companys who generally have their own domain name. So, then, these domains, I need to forward to my one IP address for myFarmMachinery.com
1
7893
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 Afternoon from my form i used this code. Response.Redirect("showdetails/" + a); in my Web.config <system.webServer>
0
9587
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.