0

I have website called http://example.com which is pointing to my public_html directory. I want my website should work with http://example.com/cms URL . And http://example.com/cms should point to public_html directory. Is it possible without creating sub directory on website root?

How can I do this with .htaccess ?

Any help will be appreciated.

Thanks.

2
  • Why not just create and use this cms directory ?
    – Croises
    Sep 26, 2017 at 15:33
  • Actually, it is not allowed to do. we need to do this with .htaccess rewrite Sep 27, 2017 at 8:29

1 Answer 1

0

Because you did not provide any details about the CMS you want to use, I can only provide a generic .htaccess file. If your CMS comes with some special rewrite rules you may have to adapt this.

RewriteEngine on
RewriteBase /

# redirect to /cms if not rewritten internal
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !^/?cms(/.*)?$
RewriteRule ^/?(.*)$ /cms/$1 [R=301,L]

# rewrite to root directory if URL starts with /cms
RewriteCond %{REQUEST_URI} ^/?cms(/.*)?$
RewriteRule ^.*$ %1 [L]

Just put this .htaccess file in your public_html folder where your CMS is installed. If you call your Website http://example.com you will be redirected (301) to http://example.com/cms and any URL that begins with /cms will internally redirected to your root folder. You do not have to create a /cms subfolder.

I did test this positive on a Ubuntu 16.04.03 LTS Server with Apache 2.4.27.

3
  • i have used this code it always shows 404 if i will open url example.com/cms Sep 28, 2017 at 3:45
  • Do you have mod_rewrite enabled and do have the right to use .htaccess? Sep 28, 2017 at 12:52
  • Yes i have mode_rewrite enabled also used right .htaccess Oct 3, 2017 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.