Implementation of URL REWRITE technology in Apache

xiaoxiao2021-03-06  47

Recently, our company's website is optimized. To use a better technology, the original PHP dynamic form of web files can be more easily incorporated by Google and other search engines, and we have adopted some improvements: For example, in the background uses the PHP program to change the original file to HTM content; use Apache's path_info technology, but it is not strong enough to determine the URL REWRITE technology in Apache to try it.

I have already told it, but I have never known how to achieve it. I bite the teeth today, I have turned the article related articles, and finally achieve some basic functions:

1, modify http.conf

In the root directory you want to modify the website:

DEFAULTTYPE Application / X-httpd-php RewriteEngine ON # Marsh Options Followsymlinks # must shutriterule /news/ (/d )/.html /news/.php/?id= $1 [n, l] # rule ALLOWOVERRIDE ALL

2, first modify http.conf

DefaultType Application / X-HTTPD-PHP

Options Followsymlinks

ALLOWOVERRIDE ALL

Then build a .htacess file in this directory, its contents are as follows: RewriteEngine on shutriteBase / WebsampleEngine on shutriteBase / WebsampleEngine on rebase / aboutRiterule news / (/ d ) /. Html news / .php /? id = $ 1 [n, l]

This enables the ability to resolve http://localhost/news/1000.html to http: //localhost/news.php? Id = 1000

Appendix: (a website .htacess file)

-------------------------------------------------- -----------------------------

ErrorDocument 401 / Error.phprewriteEngine on shutritebase /websampleEngine on shutritebase /websampleEngine on shutritebase /websampleEngine on shutritebase /WebsampleEngine/urlrewrite/power-for-less.com/

#Show category # REWRITERULE ^ ((Laptop ([^ /] *)) | (((DIGITAL)?).? Camera ([^ /] *)) | (Power ([^ /] *) | (PDA ([^ /] *)) | (Mobile ([^ /] *)) | (Two-Way ([^ /] *) | (Scanner ([^ / ] *) | (MP3 ([^ /] *))) /. HTM (L?) $ babrand / .php /? fclassname = $ 1 [nc]

#Show Brands # REWRITERULE ^ (Laptop ([^ /] *)) / ([^ /] ) /. HTM (L?) $ series / .php /? fclassname = $ 1 & fb_babrand = 3 [nc] REWRITERULE ^ Camcorder ([^ /] *)) / ([^ /] ) /. HTM (L?) $ series / .php /? fclassname = $ 1 & fb_babrand = $ 3 [NC] REWRITERULE ^ ((DIGITAL).). Camera ([^ /] *)) / ([^ /] ) /. HTM (L?) $ series / .php /? fclassname = $ 1 & fb_babrand = $ 5 [nc] REWRITERULE ^ (Power ([^ /] *) / ([^ /] ) /. HTM (L?) $ series / .php /? fclassname = $ 1 & fb_babrand = $ 3 [nc] REWRITERULE ^ (PDA ([^ /] *)) / ([^ /] )/.htm (l ?) $ series / .php /? fclassname = $ 1 & fb_babrand = $ 3 [NC] REWRITERULE ^ (Mobile ([^ /] *)) / ([^ /] ) /. HTM (l?) $ series / .php /? fclassname = $ 1 & fb_babrand = $ 3 [nc] REWRITERULE ^ (TWO-WAY ([^ /] *)) / ([^ /] ) /. HTM (L?) $ Series / .PHP /? FclassName = $ 1 & fb_babrand = $ 3 [NC] REWRITERULE ^ (Scanner ([^ /] *)) / ([^ /] ) /. HTM (L?) $ series / .php /? fclassname = $ 1 & fb_babrand = $ 3 [NC] REWRITERULE ^ (MP3 ([^ /] *)) / ([^ /] ) /. HTM (L?) $ Series / .php /? Fclassname = $ 1 & fb_babrand = $ 3 [NC ]

转载请注明原文地址:https://www.9cbs.com/read-117510.html

New Post(0)