If someone tries to open a non-existent file, they’ll be redirected to the error page I have set up in cPanel.
How can I set the path to be forwarded through to the domain I’m using for my error pages?
If someone tries to open a non-existent file, they’ll be redirected to the error page I have set up in cPanel.
How can I set the path to be forwarded through to the domain I’m using for my error pages?
Not quite sure what you mean. Can you give an example?
It’s fairly simple. If someone visits files.rydercragie.com/blablablablabla they’ll be redirected to my error page, which is RyderCragie.com. How do I set it to forward them to RyderCragie.com/blablablablabla? (Or whatever they type.)
I’m guessing it can be done with .htaccess, but I don’t know how.
I’d try this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([a-z0-9]+)$ https://rydercragie.com/$1 [NC,L,R=404]
I did test this, it works. See wkbl.cf/rydercragie-com/randomstringthatdoesnotexist. The only file that does exist is index.html
.
Just added it & I’ve left my error pages as they were. Not sure what half of this stuff is in my .htaccess file.
Line 1: Display errors (such as PHP Errors)
Line 2: Defines Character encoding (Deprecated)
Line 3: Set the timezone (You set it to Europe/London)
Lines 4-8: Error Page Redirects (from your second screenshot)
Line 9: RewriteEngine
is turned on
Lines 10-12: Redirect to HTTPS
Line 13: Check for HTTPS
Line 14: Check if the requested file does not exist
Line 15: Redirect to https://rydercragie.com/
(plus the pathname) with a 404 header.
Personally, I think you can remove Line 13. You do not need to check for HTTPS to redirect a non-existent file, especially after you have redirected everything to HTTPS.
Okay but it’s not forwarding the path. Why?
It’s not forwarding the path because ErrorDocument is defined before your custom code. You have two solutions: Remove ErrorDocument or move it to the end of the .htaccess.
I removed the error pages in cPanel and it got rid of them from the .htaccess file. But now it redirects to an InfinityFree error. Why?
Which InfinityFree Error does it redirect to? I’m guessing 500.
Try removing line 8.
Will do.
This might be because an ErrorDocument was defined in a parent directory. Try putting your ErrorDocument at the end of the .htaccess after all of your Rewrites.
I made a working example on my site: https://wkbl.cf/rydercragie-com/thispagedoesnotexist with this .htaccess code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([a-z0-9]+)$ https://rydercragie.com/$1 [NC,L]
and this is the .htaccess code in the parent dir:
php_value display_errors On
php_value mbstring.http_input auto
php_value date.timezone America/New_York
Protocols h2 http/1.1
<FilesMatch ".txt">
Require all denied
</FilesMatch>
ErrorDocument 400 /http.php?n=400&t=Bad%20Request
ErrorDocument 401 /http.php?n=401&t=Unauthorized
ErrorDocument 403 /http.php?n=403&t=Forbidden
ErrorDocument 404 /http.php?n=404&t=Not%20Found
ErrorDocument 500 /http.php?n=500&t=Internal%20Server%20Error
ErrorDocument 503 /http.php?n=503&t=Service%20Unavailable
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www.wkbl.cf [NC]
RewriteRule ^(.*)$ https://wkbl.cf%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^/?([a-z0-9]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^/?([a-z0-9]+)$ $1.html [NC,L]
RewriteCond %{REQUEST_FILENAME}.htm -f
RewriteRule ^/?([a-z0-9]+)$ $1.htm [NC,L]
<IfModule mod_headers.c>
Header set Strict-Transport-Security "max-age=63072000; preload"
</IfModule>
Hope this helps your debugging.
Okay. I added the error pages back and moved them to the bottom. It’s still not working. Sorry if I’m misunderstanding.
No, you aren’t misunderstanding. I’m confused along with you.
Right now, I can’t think of anything else to do.
There are no problems with the .htaccess code.
You could try removing ALL ErrorDocuments in /files.rydercragie.com/htdocs/.htaccess
and /.htaccess
and see what it does.
I am no .htaccess genie, but this should work.
Oh no. Now I’m getting server errors when I visit the domain.
Help!!! I’ve put it back to how it was but now it’s broken. What happened?!
Maybe I need to add line 8 back from before?
Try that, but it was only checking for https.