[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SEO URL Layout w/ RewriteMap

Posted on 2009-02-17
12
Medium Priority
?
903 Views
Last Modified: 2013-11-10
I have a client that wants to convert their old URL site address to something that is more SEO friendly without having to redo their entire website and directory path structure. Since there are several hundred files based on multiple mapping codes, I am using the RewriteMap Directive for the full name of the Country, State, City, Listing and Location codes when identified from the old URL listing and rewrite the URL to the SEO branded way.

Original URL: http://mysite.com/classic/us/ga/atl/0/abc.shtml
SEO URL: http://mysite.com/US/Georgia/Atlanta/Dining/10_Degrees_South

What do I need to do to have the following work:
1) In the browser, display the SEO URL but behind the scenes... display the original URL path contents to the user's browser.

2) If someone goes to the SEO URL, it keeps the SEO URL browser address, but displays the original URL path contents to the user's browser.

RewriteEngine  On
   RewriteMap    country  txt:/web/mysite.com/htdocs/TEST/seo_country.txt
   RewriteMap    state      txt:/web/mysite.com/htdocs/TEST/seo_state.txt
   RewriteMap    city        txt:/web/mysite.com/htdocs/TEST/seo_city.txt
   RewriteMap    listing     txt:/web/mysite.com/htdocs/TEST/seo_listing.txt
   RewriteMap    location     txt:/web/mysite.com/htdocs/TEST/seo_location.txt
   RewriteRule   ^/TEST/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?(.*)  ${country:$1}/${state:$2}/${city:$3}/${listing:$4}/${location:$5} [L]

Open in new window

0
Comment
Question by:Michael Worsham
  • 7
  • 5
12 Comments
 
LVL 29

Author Comment

by:Michael Worsham
ID: 23662655
And for those wondering -- mod_proxy is not an option for this.
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 2000 total points
ID: 23663265
So you have already the mapping "request of /US/Georgia/Atlanta/Dining/10_Degrees_South -map to-> /classic/us/ga/atl/0/abc.shtml working through your RewriteMaps?

> without having to redo their entire website and directory path structure.

I.e. an output filter must change all generated HTML source code, so that all <a href="..."> references are pointing to the new location (/US/Georgia/Atlanta/Dining/10_Degrees_South). You could use mod_ext_filter to connect to an external program (e.g. self written perl script) which performs the source code transformations /classic/us/ga/atl/0/abc.shtml --> /US/Georgia/Atlanta/Dining/10_Degrees_South via e.g. lookups and preg_replace.

There are some modules like mod_publisher or mod_proxy_html (can work outside of reverse proxies, too) available which can perform source code transformations, but as far as I can see none of them can perform any lookups.
0
 
LVL 29

Author Comment

by:Michael Worsham
ID: 23663400
No. I don't have mapping request working yet. If you attempt to go to... http://mysite.com/classic/us/ga/atl/0/abc.shtml -- it tries to redirect to -- http://mysite.com/US/Georgia/Atlanta/Dining/10_Degrees_South instead. This is not the intended end turn setup.

I want to change the browser's URL to show the change to the new format (i.e. http://mysite.com/US/Georgia/Atlanta/Dining/10_Degrees_South), but in a way do something like a URL mask/cloak that presents the http://mysite.com/classic/us/ga/atl/0/abc.shtml data to the browser instead while keeping the SEO URL in the browser window.

Example: If you go to 'http://mysite.com/US/Georgia/Atlanta/Dining/10_Degrees_South', you are actually seeing 'http://mysite.com/classic/us/ga/atl/0/abc.shtml' instead but your browser's URL is showing 'http://mysite.com/US/Georgia/Atlanta/Dining/10_Degrees_South'.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 29

Author Comment

by:Michael Worsham
ID: 23663467
Attached is a combined copy of the SEO Map data files that the above code uses.


seo-mapfile-layout.txt
0
 
LVL 29

Author Comment

by:Michael Worsham
ID: 23664150
Upon further research, it seems that mod_rewrite cannot be used to change the URL that the visitor sees in his/her browser address bar unless an external redirect is invoked. Mod_rewrite works on requested URLs after the HTTP request is received by the server, and before any scripts are executed or any content is served. That is, mod_rewrite changes the server file path and script variables associated with a requested URL, but has no effect whatsoever on the content of 'pages' output by the server.

The real problem is that the 'US/Georgia/Atlanta/Dining/10_Degrees_South' portion does not exist on the server-side at all. It is a simple layout for making it easier to read via the browser and for SEO needs. Only the 'TEST/us/ga/atl/0/abc.html' directories and file actually exists.

So I guess my question now is...

1) How does one trigger the 'external redirect' script under Apache?
2) How does one go about doing what I am trying to do w/o the use of mod_proxy?

I have posted a copy of the Virtual Host I am toying with for testing purposes.

<VirtualHost *>
   ServerName mysite.com
   DocumentRoot /web/mysite.com/htdocs
   ErrorLog /var/web/mysite.com/error_log
   CustomLog /var/web/mysite.com/access_log combined
 
   RewriteEngine  On
   RewriteMap country  txt:/web/mysite.com/htdocs/TEST/seo_country.txt
   RewriteMap state    txt:/web/mysite.com/htdocs/TEST/seo_state.txt
   RewriteMap city     txt:/web/mysite.com/htdocs/TEST/seo_city.txt
   RewriteMap listing  txt:/web/mysite.com/htdocs/TEST/seo_listing.txt
   RewriteMap location txt:/web/mysite.com/htdocs/TEST/seo_location.txt
 
   # Incoming URI is seen as http://mysite.com/TEST/us/ga/atl/0/abc.html
   # Run through Rewrite conditioning portion to change to new SEO URL listing instead
   # Example: http://mysite.com/US/Georgia/Atlanta/Dining/10_Degrees_South
 
   RewriteCond %{THE_REQUEST} ^TEST/${country:$1}/${state:$2}/${city:$3}/${listing:$4}/${location:$5}
 
   # Now display in browser the SEO URL address (as seen in example)
   # But retrieve data information from original URI address
 
  # RewriteRule ^/TEST/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?(.*)  ${country:$1}/${state:$2}/${city:$3}/${listing:$4}/${location:$5} [L]
  # Redirect / %{REQUEST_URI}
 
    RewriteRule ${country:$1}/${state:$2}/${city:$3}/${listing:$4}/${location:$5} %{REQUEST_URI} [L]
 
   <Directory /web/mysite.com/htdocs>
      Options Indexes FollowSymLinks Multiviews +Includes All
      AllowOverride All
  </Directory>
</VirtualHost>

Open in new window

0
 
LVL 27

Assisted Solution

by:caterham_www
caterham_www earned 2000 total points
ID: 23664782
>> it seems that mod_rewrite cannot be used to change the URL that the visitor sees in his/her browser address bar unless an external redirect is invoked. Mod_rewrite works on requested URLs after the HTTP request is received by the server, and before any scripts are executed or any content is served. That is, mod_rewrite changes the server file path and script variables associated with a requested URL, but has no effect whatsoever on the content of 'pages' output by the server.<<

Correct, that's why you'll need an output filter to change the links in the html source code (or you change all <a href=""> references in all files by hand; that doesn't mean you need to rename the files/change the folder structure -- the references can point to your non-physically existent paths -- but you won't be able to browse through the files w/o using mod_rewrite).


> 1) How does one trigger the 'external redirect' script under Apache?

With the R flag, for the status code 301 R=301 like

RewriteRule ^pattern-to-match http://server/new-value [R=301,L]

But redirecting alone is not enough for SEO. Your HTML links should point to the new location, too.
0
 
LVL 29

Author Comment

by:Michael Worsham
ID: 23665383
The problem is that the HTML code cannot be altered what so ever. We are talking about 20 to 30,000 static html files that would have to be touched. Not a likely concept for the developers. We need an in-line solution to do the URL masking while allowing the data file themselves to remain untouched.
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 23665451
So a self-written output filter would would be the last option to change the html source w/o touching the files itself. That decreases the performance of static files, of course.
0
 
LVL 29

Author Comment

by:Michael Worsham
ID: 23666643
Is it possible to get around the filter requirement by using mod_proxy instead?

The reason I am asking is we are trying to find the quickest and simplest way to parse the old original URL, convert it to the new SEO URL layout based on the country, state, city, listing type and location while doing something like a URL masking/shadowing so the user doesn't know they are still viewing the old (original) URL layout.

Plus my skills in Perl is pretty much non-existent for doing a parse/filter on the fly.
0
 
LVL 27

Assisted Solution

by:caterham_www
caterham_www earned 2000 total points
ID: 23668805
A proxy situation wouldn't help; the proxy doesn't modify your html source code and the 3rd party modules mentioned above can only use information present in the (old) URL to put it into the new URL but they can't resolve 'ga' to 'Georgia' (unless you hard code that in a transformation rule for each possible link).

The program isn't limited to a perl script, it must be sthg. which is executable (e.g. via shebang line).
0
 
LVL 29

Author Closing Comment

by:Michael Worsham
ID: 31547910
Thanks for your help. This helps point me (and the developers) in the right direction for explaining this to our client.
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 23680857
BTW: May be - since mod_proxy_html ( http://apache.webthing.com/mod_proxy_html/ ) is open source (GPL) - it's worth to implement some mod_rewrite like lookup functions into the directive ProxyHTMLURLMap. Currently only environment variables can be retrieved.

mod_proxy_html can run outside of a proxy environment via

SetEnv PROXY_HTML_FORCE
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses
Course of the Month18 days, 2 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question