Beginner Apache URL Rewrite Question

2019-05-29 04:12发布

I'm just trying to figure out if I'm on the right path - additional details on rewriting the URL in my example would be appreciated.

I have installed a CMS program and would simply like that www.example.com be pointed to www.example.com/cms. I just want to know if URL rewriting through apache is the best way to accomplish this?

Thank you.

2条回答
该账号已被封号
2楼-- · 2019-05-29 04:31

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>
查看更多
来,给爷笑一个
3楼-- · 2019-05-29 04:48

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.

查看更多
登录 后发表回答