Ten URL rewriting tips and slips
Article by Saul Dobney
URL rewriting is the great capability to use proper web page names for dynamically created pages. As an alternative of http://www.notanant.com?id=123&type=abc in the URL on the handle bar site visitors would just use and see http://www.notanant.com/assist. It really is less difficult to don’t forget and makes dynamic sites less complicated to use and navigate.
But regardless of the benefits there ought to be 1000′s of web developers and internet hosts who have appeared into it, or even experimented with it, and believed that it is as well difficult to get operating. Apache alone has some extremely great descriptions, but the problem is in obtaining URL rewriting to operate in a particular circumstance, not just the examples.
Right here are ten hints and ideas to get you from the documentation to doing work with dwell URL rewrites on Apache
1. Get the route correct. If you are utilizing http.conf for rewriting don’t forget there is a major slash (/). For.htaccess this isn’t really essential.
two. Flip rewrite logging on so that you can see what the rewrite motor is performing from the rewrite log files.
RewriteLog /route/to/logfile/log.txtRewriteLevel five
three. When starting out use the compelled redirect selection [R=302] for your policies so the browser will present the genuine page redirected to and not just the original URL. When it is operating take away the redirect and the visitor will only see the URL typed into the browser
RewriteRule ^(.*)$ /mypage.html [R=302]
four. Now verify rewriting is on and functioning by redirecting every little thing to a single simple HTML file to start with
RewriteEngine OnRewriteRule ^/(.*)$ /mypage.html [R=302] # httpd.conf version
OR
RewriteEngine OnRewriteRule ^(.*)$ mypage.html [R=302] #.htaccess model
five. Examination locally initial. Use rewrites for the localhost exam server on the growth program ahead of moving to the server. This indicates the rewrite guidelines and normal expressions can be doubled checked
six. Use a regex expression checker to create the standard expressions offline. It will be more rapidly to debug then test them in the RewriteEngine as soon as they are correct
7. In standard expressions the. represents a wildcard merchandise. To test for a file ending in.html in a normal expression a backslash is required prior to the level so ^.html$ matches any file ending in.html
eight. Some symbols in standard expressions behave in distinct methods in different places. This causes confusion. A ^ at the start marks the commence anchor. A ^ in sq. brackets indicates Not.
For instance [^-9]* matches any character that is not -nine.
To get a Not on the complete expression requires! so!^.html$ matches any files that do not have.html
9. When relocating to the dwell server if virtual hosts are on, every virtual host that ought to have the rewrite rule wants
RewriteEngine onRewriteOption inherit
within the virtual host definition to pick up the rewrite rule. If this is not the circumstance the rule will not perform.
ten. For intricate rewriting according to the final results of a database search and from there to diverse scripts use a relay script to keep away from the complexities of linking the rewrite engine to the database right
For case in point:
Each of http://www.notanant.com/support, http://www.notanant.com/information and http://www.notanant.com/blog site rewrites to relaypage.php?location=assist or relaypage.php?location=news and many others.
relaypage.php normally requires the value of spot and then appears it up in the database. The PHP include command to execute the proper script rathert than making use of a redirect, so the customer still sees the proper page in their URL. There is 1 trick the following which is that get variables need to have to be set explicitly prior to the include assertion as it is not feasible to use contain “page.php?id=123″
$ _GET['id']=123include “page.php”
Making use of the consist of means the page is passed again to the customer as anticipated and implies that you can redirect to distinct scripts with diverse values if requirements be.
Saul Dobney is head of growth at Notanant (http://www.notanant.com) a net-application that helps make it simple for any person to develop communities of sites and sites for communities.
thirteen
thirteen
thirteen
thirteen
thirteen
thirteen
Shortlink for this post: http://seocompletesolution.com/seo/?p=253














I have been a regular reader of your blog. I find it very interesting when you talk about such topical issues. I too have a blog of my own and you really inspire me to write quality stuff.
Fab post and an enjoyable read, came across it on yahoo while doing some research in to this topic. i lookforward to reading alot more articles from you.