About how url overrides are implemented

146 3

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.

3 Answers

81 4

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"
 <!-- 这是UrlRewrite的配置 -->

Here's the urlrewrite. Xml configuration.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC"-//tuckey.org//DTD UrlRewrite 3.2//EN"
 Configuration file for UrlRewriteFilter
 <from>/index</from><!-- 地址栏里会显示http://localhost:8080/工程名/index -->
 <to>/index.action</to><!-- 实际调用的是index.action -->

I want to help you.

139 0

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.

56 0

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:

http://www. Yoursite. com/product/13/3/..

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.

Example example

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.

rewriteengine on

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