Can someone please tell me what URL rewriting is? I don't understand . . . a client is asking me to rewrite his URLs.
URL Rewriting
Collapse
This topic is closed.
X
X
-
go@thescriptsmailer.comTags: None -
Ed
Re: URL Rewriting
go@thescriptsma iler.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 =----
-
Bill Karwin
Re: URL Rewriting
go@thescriptsma iler.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.
Comment
-
Hemant
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
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,
Comment
-
Bill Karwin
Re: URL Rewriting
go@thescriptsma iler.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.
Comment
-
Ja NE
Re: URL Rewriting
Bill Karwin <bill@karwin.co m> 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($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
--
Comment
-
feed_sheep
Re: URL Rewriting
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" <paperhat@zoomi nternet.net> wrote in message
news:1131758972 _317@spool6-east.superfeed. net...[color=blue]
> go@thescriptsma iler.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]
Comment
-
Philip Ronan
Re: URL Rewriting
"feed_sheep " wrote:
[color=blue]
> 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?[/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?conte nt=alumni
....then you might have more luck.
--
phil [dot] ronan @ virgin [dot] net
Comment
Comment