For the url, the url rewriting guide on is an introduction to this feature, all in english, looking at a tough, and a.
The project is a jsp web site that's built on the j2ee.
The development kit is eclipse.
My development framework is struts 2, and the steps to use urlrewrite are to introduce the relevant packages first.
Then use the following configuration in web. Xml.
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 这是UrlRewrite的配置 --> <filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class> org.tuckey.web.filters.urlrewrite.UrlRewriteFilter </filter-class> </filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--结束--> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> <!--重要--> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
Here's the urlrewrite. Xml configuration.
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE urlrewrite PUBLIC"-//tuckey.org//DTD UrlRewrite 3.2//EN" "http://tuckey.org/res/dtds/urlrewrite3.2.dtd"> <!-- Configuration file for UrlRewriteFilter http://tuckey.org/urlrewrite/ --> <urlrewrite> <!--以index为例--> <rule> <from>/index</from><!-- 地址栏里会显示http://localhost:8080/工程名/index --> <to>/index.action</to><!-- 实际调用的是index.action --> </rule> <rule> <from>/admin</from> <to>/blog/admin.jsp</to><!--实际访问的为admin.jsp--> </rule> <!--网址中有变量的时候--> <rule> <from>/index/([sS]*)$</from><!--以$代替变量，变量支持正则表达式--> <to>/index.action?param=$1</to><!--用$1调用变量--> </rule> <!--网址中有多个变量的时候--> <rule> <from>/essay/([sS]*)/([sS]*)$</from><!--多个变量用'/'分割--> <to>/main.action?date=$1&id=$2</to><!--变量与变量之间用'&'连接，重要--> </rule> <!--以下不用管--> <outbound-rule> <from>/rewrite-status</from> <to>/test/status/</to> </outbound-rule> </urlrewrite>
I want to help you.
You can find the chinese version, and you've to see it.
http://man. Chinaunix. net/newsoft/Apac..
Open the head, say how to implement a url rewriting:
Fi & t define a unified entry main. Jsp, all requests sent to apache are forwarded to it, as follows:
Rewriterule ^/( js | css | images )/(. + ) $/$ 1/$ 2? % % 7bquery_string % [.
Rewriterule ^ (. + ) $/main. jsp? u = http://% % 7bhttp_host % response $ 1 &.
Fi & t row, all static content requests static files directly.
The second line, through the url of the request to the main. Jsp, and query string, then you can use the hard disk files to respond to this request.
For example, http://www. Domain. com/js/jquery. Js asynchronously requests the jquery. Js file on the hard disk.
And the user list page http://www. Domain. Com/users? type = 1 is forwarded to.
Information on user 1 displays the page http://www. Domain. com/user/1? type = 1 is forwarded to.
In the main. Jsp page, you can get the query string.
Argument u is http://www. Domain. com/user/1 clonezilla, type.
To split u, you can get user and 1, forward user 1 to.
Can get information about user 1.
The following article is written by 360weboy, the original address: combined with mod rewrite and php to generate optimized seo url. 360weboy - focus on php web development, web, and build professional php community. Hopefully this article is helpful to you, interested in adding 360weboy 's qq group 197642724, or looking at 360weboy 's sina or tencent webo together with the idea of finding the
Although I'm not a professional seo optimization, but in some of the projects I've reached, we know some ways to implement seo. To generate a link to a user and search engine friendly url, there are two ways I've already seen it:
1. Combined mod rewrite and php generate optimized seo url.
2. In the application 's front controller, the url is parsed by means of the path, and then the request distribution ( dispatch ) to the specific controller for the request is processed.
This article mainly introduces how to combine mod rewrite and php to generate optimized seo urls. For dynamic web sites, static url comparisons are beneficial to search engines, which are important parts of site seo.
First, let's look at a //www that's annoying for a search engine - http: Yoursite. Com/product. Php? p.
Clearly, when users look at one of the urls above, it isn't clear that it's currently looking at the product. So, we've to change the url to the following form of link:
When the user sees the above url, at least knowing the current product is 2gb mp3 player. We use apache mod rewrite to implement the transformation of the above urls.
I often summarize the transition process: what's looking for and where to go?
, what's mod rewrite?.
The explanation on wikipedia is as follows:Url rewriting ( url ) is a rest related technology that can be used in web server to convert the url provided by the user, and then pass in the web server handler.
The most common use is to convert a set of url hierarchies to a url with query string, or reverse conve & ion, for example:
http://www. Somebloghost. com/Blogs/Pos..
After the url overrides, you can become:
http://www. Somebloghost. com/Blogs/200..
Another example, the following url:
http://www. Somehost. com/Blogs/2006/12..
After the url overrides, you can convert to:
http://www. Somehost. Com/blogs. Aspx? ye..
Therefore, users can use a direct way to enter urls ( this is the main goal of rest ), one of the search engine optimization ( seo ) practices. Application developers can use this mechanism to hide parameters to prevent malicious users on the network from collecting information that's useful to launch.
My understanding is that when the user accesses your program through a url, the web server checks whether the link to the request conforms to a certain rule. This means that the request is eventually processed by the product. Php, but the user or search engine sees a completely different url.
The steps to override the url of the
So far, we've seen what's mod rewrite. Next, we're going to learn how to rewrite urls. The first step is to create a. Htaccess file and place the file in the root directory of your site ( for linux only ), which seems to have no effect on win type. Next, you need to add the following code in. Htaccess:
RewriteEngine on RewriteRule ^article/([0-9]+)/([0-9]+)/(.*?).html$/article.php?articleid=$1&categoryid=$2
Let's look at what the two lines of code mean.
The first line code tells the web server to override the url, or the server will throw 404 errors. Don't forget to add the code first when you specify the override rule.
Rewriterule ^product/( [ 0-9 ] + )/( [ 0-9 ] + )/(. *? ). Html $/product.? productid = channel 1 & amp; hue = $ 2.
The second line code is divided into two parts: The fi & t part is a regular expression, and the second part is a dynamic url. Combined with the ^product [ 0-9 ] + )/( [ 0-9 ] + )/(. *? ), html $, the request is directed to the product. Php? productid = $ 1 & = _. As I mentioned earlier, I understand what's looking for the first part, and the second part is understanding.
The first part of the is looking for what?
The following regular expressions are defining what's looking for. Let's separate the entire regular expression from the url ://www. Yoursite. com/product/13/3/.:
1. The product tells the web server that the view matching url must begin with the string of the product. This matches the product in the url.
Next ( [ 0-9 ] + ) tells the web server that the is immediately followed by 0 9, which appears at least once, and 3. Is the matching id. For example, this product id can be 1, 20, 567, etc.
4. Continue to match/, then a ( [ 0-9 ] + ), as in the case, to match the taxonomies.
5. Continue match/, (. *? ). Html matches any of the html characte & that are prefixed by any number or word.
Finally, indicates the end of matching match string
The second part of the ?
This isn't going to be speaking, the conventional dynamic url parsing.
All right, so it's so simple, how to use php to send the url in the project to seo form, and believe everyone knows how to do it.
In the above articles, 360weboy, the original address: combined with mod rewrite and php to generate optimized seo url. 360weboy - focus on php web development and web, trying to build a professional php community. Hopefully this article is helpful to you, interested in adding 360weboy 's qq group 197642724, or looking at 360weboy 's sina or tencent webo together with the idea of finding the