简体   繁体   中英

URL rewrite in apache server

I'm in a situation where my web page have the following types of URL's

http://mysite.com/?type=home
http://mysite.com/?type=aboutus
http://mysite.com/?type=contactus

For the end users I need it to display like the following:

http://mysite.com/home
http://mysite.com/aboutus
http://mysite.com/contactus

This means, the user is not aware that the URL have a request parameter "type" in it.

I'm not sure it is possible or not.

Please help me to get to a solution.

EDIT : I searched lots of websites to learn URL rewrite by using .htaccess, But didnt able to make them working in my server.

Place this in you .htaccess file

RewriteEngine On
    RewriteRule ^([a-zA-Z0-9-+/]+)$ ?type=$1
    RewriteRule ^([a-zA-Z0-9-+/]+)/$ ?type=$1

Yes it is absolutly possible.

Your have to be sure your hostprovider has enable URL rewriting (I don't really remenber but I'm sur you can find help on Internet to verify that).

You have to create an ".htaccess" file at the root of your site.

Put this content in it :

tell the server to follow symbolic links :

Options +FollowSymlinks

activate the rewrite module :

RewriteEngine on

Rule for rewrite url

RewriteRule ^([a-z]+)$   /index.php?type=$1 [L]

Note this is just a qucik exemple you may want to look "url rewriting tutorial" on Google.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM