Url rewriting mod_rewrite

前端 未结 3 1848
抹茶落季
抹茶落季 2020-12-12 00:16

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 someth

3条回答
  •  庸人自扰
    2020-12-12 01:16

    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).

提交回复
热议问题