Add mod_rewrite module to Apache

Source: Internet
Author: User

There is a new requirement recently:

 

Like Weibo addresses, the implementation of short addresses makes it easier to promote wireless advertisements;

 

Knowledge Point

1. Create a ing between a URL and a segment address, either in cache or in MySQL;

Create Table 'invalid url '(

'Id' mediumint (8) Not null auto_increment,

'Parm' char (30) not null default '', URL parameter

'Short 'char (10) Not null, short address

Primary Key ('id ')

) Engine = MyISAM default charset = utf8;

If a URL exists, it is read. If no URL exists, it is created;

Create a rule to generate a short address by ID;

2. How to generate a short address:

3, rewrite

The final short address access format is as follows:

Http: // domain/beedd

Then, you need to perform rewrite to jump to a file and then process it:

This can be done in the/redirect/index. php file;

I encountered some problems during rewrite: My testing environment is nginx test OK, but the online environment is Apache, And the rewrite module is not compiled. Depressed;

 

Add the rewrite module!

 

// InApacheFind the mod_rewrite.c file in the source code installation directory

# Find.-Name mod_rewrite.c

 

// Enter the directory containing the mod_rewrite.c File
# Cd modules/mappers/mod_rewrite.c

 

// Apxs should specify the absolute path, in which you are currently usingApacheIn the bin directory
 
#/Usr/local/Apache/bin/apxs-C mod_rewrite.c

#/Usr/local/Apache/bin/apxs-I-a-n mod_rewrite
Mod_rewrite.la

 
 
If there are no errorsApacheTo compile a mod_rewrite.so file.

 


 
Edit the httpd. conf file and confirm that the httpd. conf file contains the loading statement mod_rewrite.so,

As follows:
Loadmodule rewrite_module modules/mod_rewrite.so
 
At this time, yourApacheRewrite is supported.
 
Note: After this is done, remember to restart the server.Apache.

. Possible Problems
 
Httpd: syntax error on line 54 of/usr/share/Apache-2.2.11/CONF/httpd. conf:

 

Can't locate API module structure
'Mod _ rewrite_module 'in file/usr/local/Apache/modules/mod_rewrite.so:
/Usr/local/Apache/modules/mod_rewrite.so: Undefined Symbol: mod_rewrite_module

 
Modify httpd. conf and set
 
Loadmodule mod_rewrite_module modules/mod_rewrite.so
Change
 
Loadmodule mod_rewrite modules/mod_rewrite.so
 
If this error occurs
Syntax Error on line 329 of/usr/local/apache2/CONF/httpd. conf: Can't loacte API module staructure 'mod _ rewrite_module 'In File
 
/Usr/local/Apache/Modules/mod_rewrite.so:/usr/local/Apache2/lib/libapr- 0. so.0: Undefined Symbol: mod_rewrite_module
 
Modify HTTP. conf
 
Originally: mod_rewrite_module written in httpd. conf
 
Change to rewrite_module
 
If you restartApacheThis error occurs. Module
Rewrite_module is built-in and can't be loaded
 
Indicates that the module is built-in. You do not need to call it again and comment it out.
# Loadmodule rewrite_module modules/mod_rewrite.so
 
######################################## #############
 
Check:
 
[Root @ WWW httpd-2.2.8] # ../bin/apachectl configtest

Syntax OK

At this time, yourApacheRewrite is supported.

 

Vim/usr/local/Apache/CONF/extra/httpd-vhosts.conf

Restart Apache

 

Test OK,

 

Done!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.