Redirect the files of a subdirectory to root folder on request

Username: epiz_30148224

[Moviespace]

Error Message

Whenever I try to reload my website from a path other than the homepage, it shows error pages.

For example, if I enter http://moviespace.rf.gd and hit enter, the website loads and works fine.
But when I enter http://moviespace.rf.gd/movie and hit enter, it redirects me to the 404 error page. I want the server to fetch all static files from the root folder irrespective of the URL.

Other Information

I went through a lot of StackOverflow posts and tried to understand the RewriteRules.
These are the changes I have made to my new .htaccess file which is stored inside the htdocs folder.

DirectoryIndex index.php index.html

RewriteEngine on

#Redirect all sub-paths to root domain. For example mydomain.com/abc to mydomain.com
#RewriteRule ^[\w-]+(/.*)$ $1 [L,R=301]
#RewriteRule  ^tv/(.*)$ /$1 [R=301, NC, L, QSA]

I’m completely new to this hosting world. Please guide me.
I would appreciate it if anyone can suggest me some good tutorials on web hosting.

Thanks

I think I understand what you mean, but I am not sure.

Maybe this?

5 Likes

This behavior happens if your website is a Single Page Application but you don’t have proper .htaccess rules set up.

When you load the home page first, the server gets the request to load the URL at /, which matches the index.html file. This loads your page. Any following pages you navigate to are handled with Javascript routing, which pushes the URL, e.g. /movie to the address bar.

But if you try to open the URL directly, the server gets the request to load the URL /movie. But since there is no file or directory named movie, it doesn’t know which content to load so it returns with the 404 Not Found error.

To fix this, you need to tell the server that any non-existent URL should result in the index.html file being loaded instead. That way, the /movie URL loads your SPA, which can then show the appropriate page.

You can do this with .htaccess rules, for example with this one:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^(.*) /index.html [NC,L]

On a sidenote, I do want to remind you that movie streaming sites are illegal and as such they are prohibited on our hosting. This also includes sites where the actual movies themselves are loaded from other servers.

5 Likes

@Admin Yes, you caught it write. It is a single-page application.

Also, I knew the cause of the issue. What I don’t know is the solution as I am a novice in this area.

Would you mind telling me which technology or tutorial I should follow to know more about web hosting and cPanel?

Thanks a lot. I really appreciate your help.

FYI, it is just an information-providing website that provides information about movies and TV shows like an overview and release date, etc.
In any form, it doesn’t do any illegal activities like streaming or downloading media illegally.

@Greenreader9 Thanks for the help.

But the blog you suggested is not much related to the issue I raised.

I’ve personally learned everything I know by my own trial and error. Except for this specific issue, you seem to have been able to figure out everything on your own as well. So I think you’re on the right track already.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.