Forum Moderators: phranque

Message Too Old, No Replies

Directory Type URL Rewrite?

         

amwd07

12:14 am on Dec 8, 2007 (gmt 0)

10+ Year Member



I must be doing something wrong, I can't get this to work?

Options +FollowSymLinks
RewriteEngine on
RewriteRule dining/town/(.*)\.php$ dining.php?town=$1

I am trying to re-write the URL below
dining.php?county=shropshire&town=telford

to:
/dining/shropshire-telford.php

Please can someone help me out with the htaccess rule?

jdMorgan

12:27 am on Dec 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you are doing wrong is not in the code. Your code is correct, but it's only half of the solution, and the other half is unacknowledged.

Change the links on your pages to the dining/town format. Then when a visitor or search engine 'clicks' this new link, your RewriteRule will 're-connect' that URL to the proper filepath needed to send the request to your php script.

In an optional third step, you may wish to redirect client requests for the old dynamic URL to the new static URL. This is not required, but often speeds removal of the old URLs from search engines results.

The links on your pages define the URLs used by Web clients, and listed in search results.

For efficiency, your rule is more properly written:


RewriteRule ^dining/town/([^.]+)\.php$ dining.php?town=$1 [L]

More here [webmasterworld.com].

Jim

amwd07

1:56 am on Dec 8, 2007 (gmt 0)

10+ Year Member



thankyou for your help

I have changed the links no to goto

{town_formatted} is my xml dataset to fetch list of towns
via php export to xml
dining/town/{town_formatted}.php

so example URL's

dining.php?town=shifnal
dining.php?town=telford
etc.

I have copied your htaccess rule
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^dining/town/([^.]+)\.php$ dining.php?town=$1 [L]

so the url which should be working is
dining/town/shrewsbury.php

if possible I would like
dining/shrewsbury.php

I still can't get this to work
I have looked at the link you have sent me but could not work out what I am doing wrong

could this be an issue with the server
I have used modrewrite before with this site.

I have also looked at a rewriting tool.
Single Page URL works but is no use to me
I need Directory Type URL to work

any ideas?

[edited by: jdMorgan at 2:04 am (utc) on Dec. 8, 2007]
[edit reason] No URLs, please. See TOS. [/edit]

jdMorgan

2:21 am on Dec 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



so example URL's

dining.php?town=shifnal
dining.php?town=telford


It is most important that you understand that these are not URLs -- or they are no longer URLs. These are now only server filepaths.

With your new "dining/town/town-name.php" link in place, the URL is "dining/town/town-name.php", and with the following RewriteRule in place, these URLs will be sent to the script file "dining.php" with a query string (php GET parameters) of "town=town-name".


Options +FollowSymLinks
RewriteEngine on
#
# Send requests for example.com/dining/town/town-name.php to server filepath dining.php?town=town-name
RewriteRule ^dining/town/([^.]+)\.php$ dining.php?town=$1 [L]

So if you have the link "example.com/dining/town/shrewsbury.php" on your page and a visitor clicks it, then his/her browser sends a request for "/dining/town/shrewsbury.php" to hostname "example.com". Mod_rewrite then forwards that request to the "dining.php" script with a name/value pair of "town=shrewsbury".

Distinguishing between URLs (used only on the Web) and filepaths (used only inside your server) is critical to making sense of this method. In the mode shown here, mod_rewrite is literally a URL-to-filepath translator, and is described as such in the Apache documentation.

You will also likely find it necessary to completely flush your browser cache after uploading any new rules to your server. Otherwise your browser will show you previously-cached results, no request will be sent to your server, and therefore, the code above will not be executed and can have no effect.

Jim

amwd07

2:35 am on Dec 8, 2007 (gmt 0)

10+ Year Member



Thanks works now apprt from layout and images

The images and file paths for stylesheet etc.
are not diplaying

I can see the reason for this is because this page is no longer being seen in the route, is there a way to resolve this without going into the relevent files and changing to absolute links?

jdMorgan

4:15 am on Dec 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two choices:

Change your image/css/js links to use server-relative links, e.g <img src="/images/logo.gif"> or canonical links, e.g <img src="http://example.com/images/logo.gif">
- or -
Add a rule to rewrite images/css/js requests which start with /dining/town to remove that path-part.

Example assuming typical image URL is actually "example.com/images/logo.gif" and that you have .gif, .jpg, .jpeg, .bmp, and .png image files:


RewriteRule ^dining/town/(images/[^.]+\.(gif¦jpe?g¦bmp¦png))$ /$1 [L]

Replace all broken pipe "¦" characters with solid pipes before use; Posting on this forum modifies the pipe characters.

The first method requires a site-wide edit of image/css/js links, while the second method introduces duplicate content -- The same content available at multiple URLs. This would only seem to be a problem if your were concerned with ranking in image search.

Also, taking steps to prevent spidering of these multiple URLs by image search robots would be wise, in order to conserve server bandwidth.

Jim

amwd07

11:45 am on Dec 8, 2007 (gmt 0)

10+ Year Member



Thankyou for all your help with this
10/10 for support & dfast responce time :)

One final thing, well maybe just some advice

My client is coming up top on google for most of his town
searches example type bridgnorth rest, no the problem is the old pages are coming up, which thanks to your help is now sorted, the question I have, is it possible to tid up these urls without loosing the rankings?

example
dining/shropshire-church%20stretton.php

to
church-stretton/
/// removing both county and dining directory?
or if that does not work keep the dining/church-stretton

don't wrorry about the %20 I have that covered in the db

is this modification possible and will the rankings stay the same, this site has a lot of backlinks, to many to ask people to change the links to the towns

Also am I right in thinking I am going to have to keep all the existing keywords the same from the old site to the new, or can I change these without effecting the position?

amwd07

9:39 pm on Dec 9, 2007 (gmt 0)

10+ Year Member



Sorry to post again but if there is a quick sollution to my final question please reply as I need to get this right for my client

Many thanks

Adam

jdMorgan

10:42 pm on Dec 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alas, solutions are rarely "quick."

I'm sorry, but I don't understand your description above or your question, and even more importantly, I do not know the context in which your question should be answered.

Your URLs must contain all of the information needed to serve the correct content, so I cannot answer whether or not a "tidied" URL as you describe could actually work properly -- I don't know the "universe" of URLs which are used on your site, or whether your "tidied" would be sufficiently unique.

In addition, if you change your URLs, then you will certainly suffer at least a temporary loss of ranking in search results. On Google, this seems to vary from a few weeks to up to a year, based on reports here, and depends on the current PageRank of each page involved, the age and TrustRank(TM) of each such page, on how many URLs are changed, and on the linking graph of these pages within the site

Jim

amwd07

11:49 pm on Dec 9, 2007 (gmt 0)

10+ Year Member



Ok sorry for being impatient

To simplify this issue

I have just 2 questions

if I keep this url for example to keep my search rankings
dining/shropshire-church%20stretton.php

is it possible
rewrite to: dining/church%20stretton
without changing any of my links almost like a redirect?

Or maybe if that is not possible would 301 redirect via htaccess damage searches?

jdMorgan

12:07 am on Dec 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if I keep this url for example to keep my search rankings
dining/shropshire-church%20stretton.php
is it possible
rewrite to: dining/church%20stretton
without changing any of my links almost like a redirect?

Almost like a redirect? If you do an internal rewrite --a URL-to-filename translation-- of URL example.com/dining/shropshire-church%20stretton.php to server filepath /dining/church%20stretton then that requires that dining/church%20stretton be a valid existing filename on your server.

If you do a permanent external 301 redirect --a URL-to-URL reassignment-- of URL example.com/dining/shropshire-church%20stretton.php to URL example.com/dining/church%20stretton then you will not "keep this URL"; you will be redirecting it, changing it in the search results, and suffering a (hopefully) temporary loss of the original URL's ranking.

If you do a temporary external 302 redirect --a URL-to-URL substitution-- then you won't really accomplish anything.

The link on the page defines the URL. Mod_rewrite can 'steer' an incoming request for that URL to a file on the server having a different name than that implied by the URL, or it can tell the client to ask again for the content using a different URL, causing a browser client to update its address bar or a search engine client to update its link database.

Jim

amwd07

12:23 am on Dec 10, 2007 (gmt 0)

10+ Year Member



Thank you you have been very helpful

with the first option if I use something like
dining/telford.php

telford.php can never be an actual file it has to be a filepath creted from a single php file i.e. dining.php

so does that mean I can't use this first option?

Also if we deside to permant external 301 then will it be safe to delete the old files. or would we have to wait until google picks up the new pages

jdMorgan

6:15 pm on Dec 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A 301 redirect essentially replaces the old URL, so there would be no need to keep the files that were associated with the old URLs.

I would strongly suggest that you carefully re-read the thread I cited in my first post above; With the experience and familiarity you've gained from this exercise so far, I think it may help you to understand what can be done, and what should be done to attain your goal. Part of it is building vocabulary, and part of it is understanding the 'direction' in which a rewrite operates, and the large difference between a URL and a file.

This more-recent thread [webmasterworld.com] may also be of use to you.

Jim