Forum Moderators: phranque
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?
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]
Jim
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]
so example URL'sdining.php?town=shifnal
dining.php?town=telford
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]
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
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]
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
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?
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
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?
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?
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
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
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