.htaccess mod_rewrite友好的网址

时间:2015-02-17 17:56:06

标签: php .htaccess

我有php文件page.php。 URLS:

  1. page.php?content=contact

  2. page.php?content=aboutus

  3. 我需要它显示如下:

    1. mysite.com/contact

    2. mysite.com/aboutus

    3. 我发现我必须.htaccess

      RewriteEngine on
      
      RewriteRule ^paginas/([^/]+)/?$ page.php?page=contact [L]
      

      尝试了很多东西..没有结果.. 感谢您的关注

1 个答案:

答案 0 :(得分:3)

尝试:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^(?:GET|HEAD)\ /+page\.php\?content=([^&\ ]+)
RewriteRule ^ /%1? [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /page.php?content=$1 [L]

首先将/page.php?content=anything重定向到/anything,然后在内部重写返回请求,例如/anything/page.php?content=anything