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 /newdirectory/CMS/...
How can we append /newdirectory/ to all /CMS/ calls?
Simply put, a redirect is a client-side request to have the web browser go to another URL. This means that the URL that you see in the browser will update to the new URL. A rewrite is a server-side rewrite of the URL before it's fully processed by IIS.
The URL rewriting module runs early in the request-processing pipeline, modifying the requested URL before the Web server decides which handler to use to process the request. The handler, which is chosen based on the rewritten URL, processes the request and generates a response that is sent back to the Web browser.
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
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
You don't need a RewriteRule (or mod_rewrite) for this. You can use a simple RedirectMatch:
RedirectMatch ^/CMS/(.*) http://tempserver.com/newdirectory/CMS/$1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With