1

I know this is silly question for you but not for me

I am using rdp for manage my account and somehow I got problem in that

Like I have my portfolio in hthocs/portfolio folder, now whenever someone visit it, i need like that

example.com

and whenever someone visit htdocs/example, i need like this

example.com/example

So i only want to redirect homepage folder in my site and other folder behave regularly

I search on internet and I found like that

RedirectMatch ^/$ /portfolio

but using this, its shows correct path like example.com/portfolio

EXAMPLE

Give you example of localhost,

htdocs
|
|--- portfolio (folder)
|--- stackoverflow (folder)

Whenever I visit localhost in browser ( internally it will redirect to htdocs/portfolio ) and when I visit localhost/stackoverflow in browser, It will redirect to htdocs/stackoverflow not in htdocs/portfolio/stackoveflow.

using RedirectMatch ^/$ /portfolio this code, I solved my problem but whenever I visit localhost, in browser its shows real path localhost/portfolio. i don't want to client know it will redirect to this folder

I use # to scroll in website but now when i click on that, it will redirect to original folder

  • I don't know what `rdp` is and I find your question quite confusing, but from what I understood you want to escape from your document root (that I suppose is `/htdocs/portfolio`). AFAIK this cannot be done: you could circumvent it by using symlinks though. – ntd May 21 '19 at 22:03
  • rdp is remote desktop protocol, i have `aws` but i dont understand any word in your comment –  May 21 '19 at 23:24
  • You **must** know what a document root is. Please, refer to https://httpd.apache.org/docs/2.4/urlmapping.html to highlight the differences between url and local path. – ntd May 22 '19 at 05:09
  • In that article, the section [Files Outside the DocumentRoot](https://httpd.apache.org/docs/2.4/urlmapping.html#outside) addresses your problem. – ntd May 22 '19 at 06:03
  • i know what document root is but i dont want to change document root path, i want to change only homepage path and other folder behave regularly –  May 22 '19 at 12:51

1 Answers1

1

You can use these rules in your site root .htaccess:

RewriteEngine On

# to internally rewrite / to /portfolio
RewriteRule ^$ /portfolio/ [L]

To fix css/js, you can add this just below <head> tag of your page's HTML:

<base href="/" />
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks @anubhava for answer but i need both condition in one, you can see my `edit` –  May 23 '19 at 12:59
  • your 2nd solution, works fine but css js not loading –  May 23 '19 at 13:05
  • I really don't know about apache things, please visit this https://stackoverflow.com/questions/8221022/css-not-loading-after-redirect-with-htaccess-rewrite-rule –  May 23 '19 at 13:15
  • You can add this just below `` tag of your page's HTML: ``. To fix css/js I have suggested and answered this multiple times on stackoverflow and it definitely works. – anubhava May 23 '19 at 13:55
  • Yes but i want to change your answer –  May 23 '19 at 16:23
  • 1
    Nice you solved your problem @StackoverflowUser using help, appreciate your help anubhava, +1 for that – Nisharg Shah May 23 '19 at 16:28
  • I approved your edit @StackoverflowUser, and hope anubhava will also except it – Nisharg Shah May 23 '19 at 16:30
  • Part after `#` is not even sent to web server and is kept as is after internal rewrite. – anubhava May 23 '19 at 18:05
  • 1
    can you help my friend on that case? https://stackoverflow.com/questions/57884652/some-url-is-redirect-to-real-destination-but-some-not-404-page-htacess-php – Nisharg Shah Sep 11 '19 at 08:19