On the end of my rope here, nothing that should be working is.
I'm new to website building and I noticed my visitors were trying to access certain pages and getting forbidden warnings eg: trying www.test.com/test you give a 403 error.
All I want to do is make it so www.test.com/test would redirect it to a test.html file in a directory right above it.
Tried doing it with .htaccess in the root directory with nothing but
redirect /test www.test.com/test.html
Doesn't work. Just gives me the 403 error.
Tried a simple index.html file to redirect with nothing but
<?php
header('Location: www.test.com/test.html');
die();
?>
But that doesn't work either.
Really not sure why both of these outright refuse to work.
header parameter should be wrapped in double quotes. like
header("Location: www.test.com/test.html");
exit();
also make sure your server recognizes your file extention as a php file if its not having a .php file extension. You can add the custom extensions by editing httpd.conf.
If I am interpreting correctly your ultimate intention, you don't need to use redirections, just try this in your .htaccess
:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.html [QSA,L]
</IfModule>
This way, every requested URL will be interpreted as if it was the same request plus .html
.
Although you could do it via a redirection, it is not necessary.
So once you have that code in your .htaccess
you just need to have the file test.html
in your root, and www.test.com/test
will serve the www.test.com/test.html
page.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.