开发者

seo friendly url`s - how to?

开发者 https://www.devze.com 2023-02-08 06:29 出处:网络
In my website I have a form from which the users can choose to search for s开发者_JS百科pecific title in news database.

In my website I have a form from which the users can choose to search for s开发者_JS百科pecific title in news database. They can choose main rubric (for example Businnes) and subrubric (for example Local)and after that to enter some string to search. After they submit the form the webpage returns the requested infromation and the url looks like this.

foo.bar/1001/234/

where 1001 is id of Businnes and 234 is id of Local

How to do so id`s to be replaced by relevant names ?

foo.bar/Businnes/Local/


This can be done using apache/htaccess/mod_rewrite, then handled by PHP

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

From there you need to use $_SERVER['REQUEST_URI'] and parse out the data you need.

The first line turns on the rewrite engine.

The second 3 lines says, if the requested file or directory does not exist, send the request to index.php

You can just explode the $_SERVER['REQUEST_URI'] to get the parts of the data you need, no regex required.


Generate an rewrite name for each zour record ( may be unique and apostrofs, spaces etc. free ) - use regexp for cleanup


You'll need to look at mod_rewrite - there is quite a handy generator for simple rewrites if you don't know Regex well


If you are running an Apache webserver - which i am assuming you are, then you need to look into MOD Rewrite.

There is a good tutorial that I have bookmarked here: http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/


is it? http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html / answer 2

0

精彩评论

暂无评论...
验证码 换一张
取 消