Beginner Apache URL Rewrite Question

谁说胖子不能爱 提交于 2019-12-06 13:53:41

Just redirecting http://example.com/ to http://example.com/cms/:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewritRule ^/?$ /cms/
</IfModule>

Redirecting all urls which otherwise would've 404d to start with /cms/:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ /cms/$1 [L]
</IfModule>

Redirecting all urls to /cms/:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^(.*)$ /cms/$1 [L]
  <Directory /var/www/html/cms/> #change this to the correct path
    RewriteEngine Off
  </Directory>
</IfModule>

That's definitely the approach I would take. I'm going to assume you're using Apache, though this can easily be done with IIS as well. You'll need to edit your .htaccess file in the root directory to do this using mod_rewrite.

<IfModule mod_rewrite.c>

   RewriteEngine on

   RewriteRule    ^(.*)$ /cms/$1  [L]

</IfModule>

This should work for what you're after. Change "cms" to whatever directory you want to rewrite to.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!