Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
769 views
in Technique[技术] by (71.8m points)

apache - Url rewriting mod_rewrite

I have the url such as:

 page.com/content.php?xname=p&yname=q&zid=1

I want to rewrite this url using apache mod_rewrite into something like:

 page.com/p/q/

note there should not be 'zid' parameter in renamed url. I know expressions are passed as GET into the original url. Is it possible to rename as above. If yes, How to achieve this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This one works fine for me and will rewrite request for /p/q/ to /content.php?xname=p&yname=q&zid=1.

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/$ content.php?xname=$1&yname=$2&zid=1 [QSA,L]
  1. This rule is to be placed in .htaccess in website root folder. If placed elsewhere some small tweaking may be required.

  2. It will not rewrite if requested URL is a real file or folder (I'm sure you do not want to rewrite images or some other pages -- I had to add such condition since I do not know what is your website structure is).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...