This issue should be solved in your webserver configuration.
I want to redirect
Apache HTTPD Server
If you use Apache, you can create a second VirtualHost for wiki.nikunj.com, with the purpose to redirect to www.nikunj.com/wiki.
With mod_rewrite:
<VirtualHost *:80>
ServerName wiki.nikunj.com
RewriteEngine on
RewriteRule ^/(.*) http://www.nikunj.com/wiki/$1 [R,L]
</VirtualHost>
With mod_alias:
<VirtualHost *:80>
ServerName wiki.nikunj.com
RedirectMatch ^/(.*) http://www.nikunj.com/wiki/$1
</VirtualHost>
Nginx
Nginx syntax is more intuitive in this case:
server {
server_name wiki.nikunj.com
rewrite ^ http://www.nikunj.com$request_uri? permanent;
}
I want to keep the URL in wiki.
Apache
You need both mod_rewrite and mod_proxy. Then, it would be something like:
<VirtualHost *:80>
ServerName wiki.nikunj.com
RewriteEngine on
RewriteRule ^/(.*) http://www.nikunj.com/wiki/$1 [R,L,P]
</VirtualHost>
Nginx
server {
server_name wiki.nikunj.com
proxy_pass http://www.nikunj.com/wiki;
}
What about short URLs?
You can use short URLs in this scenario.
You'll need two rules instead one, one for the articles (e.g. /view/$1), one for the other index.php links.
Tip: last
in Nginx and [L]
in Apache HTTPD means the current rule is the last executed. This will allow you to avoid the two rules are executed one after the other.
Documentation
- Apache: mod_rewrite documentation
- Apache: mod_rewrite for Proxying
- Nginx: HttpRewriteModule
- Nginx: HttpProxyModule