Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I installed cms at Linux server 10.0.0.1/cms/. I want to redirect every visit to 10.0.0.1/pages to 10.0.0.1/cms/pages, while hide "cms" in the URLs.

Several attempts have been tried but failed.

1> edit /etc/httpd/conf/httpd.conf

DocumentRoot "/var/www/html" -->   DocumentRoot "/var/www/html/cms"

This only works for index page. Hyperlinks in the index "10.0.0.1/cms/pages" will become unavailable in this case, as /cms/pages no longer exist in the DocumentRoot directory "/var/www/html/cms".

2> edit /etc/httpd/conf/httpd.conf

Redirect / /cms/

This will cause infinite loop 10.0.0.1/cms/cms/cms/...

Any idea on this?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

You could do this with mod_rewrite

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cms/$1 [L]

You can place this in your /etc/httpd/conf/httpd.conf inside the vhost you defined (if you have one) or in your <Directory> otherwise.

This will redirect all requests made to /cms/something to /something while still still fetching it from /cms/something.

share|improve this answer
    
Could you please provide more details? I edited httpd.conf to AllowOverride All, and then created a .htaccess file under /var/www/html, containing your scripts. It doesn't work so far. –  beicha May 16 '12 at 9:03
    
@beicha: Updated –  Bart De Vos May 16 '12 at 9:08
    
It still doesn't work, even I place this in both <Directory /> and <Directory /var/www/html> :( –  beicha May 16 '12 at 10:09
    
Take a look here: serverfault.com/questions/120488/… –  Bart De Vos May 16 '12 at 13:52
    
This method should work, although my final solution is just mv * ../, and modify some other config files. –  beicha May 18 '12 at 3:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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