URL rewrite to add a directory at start of url

前端 未结 3 1327
轮回少年
轮回少年 2021-01-05 12:22

On my website, all images/stylesheets are in the /CMS/... directory. Recently, our website shifted to new server at a temporary url where they referenced like /newdirecto

3条回答
  •  轮回少年
    2021-01-05 12:47

    Inside the .htaccess file

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/newdirectory/CMS/
    RewriteRule ^(.*)$ /newdirectory/CMS/$1
    

    This will perform a rewrite, so accessing http://www.server.com/CMS/index.html will actually serve the content of http://www.server.com/newdirectory/CMS/index.html

    Note: This solution assumes that the CMS is the only thing being served for this domain.

    If this domain is serving more than the CMS (and only the CMS should be redirected), then the following may be better:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/CMS/
    RewriteRule ^(.*)$ /newdirectory/$1
    

提交回复
热议问题