Directory navigation issue - html

files : http://i.imgur.com/M7ioQzB.jpg
So I have an html file called hello.html and a folder called hello. But if you go to website.com/hello it will come come up with a 404 error because it finds the folder and not the html file. I have a .htaccess file that looks like this..
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
But I am not sure what I can do to fix this. I want website/hello to go to hello.html and not the hello folder.

Not sure if this is the best way, but you could have an index.html page redirecting the user to the hello.html page when a user goes to the hello directory.

Try
RedirectMatch 301 ^/hello/ http://www.example.com/hello.html

Related

How to hidden name end url index.html

What I mean by last name in the url, like index.html for example the url link on my website homepage. the result is like this
https://hijaben.insomnia247.nl/index.html
I want to remove or delete the last name of the url (index.html)
I tried using the .htaccess file but it didn't work at all. Is it possible the script is wrong or the VPS doesn't support or what? the solution ..?
File .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
</IfModule>
https://www.digitalocean.com/community/tutorials/how-to-rewrite-urls-with-mod_rewrite-for-apache-on-ubuntu-16-04
Please check this out im sure it can help you with your problem sir.
https://www.linode.com/docs/web-servers/apache/how-to-set-up-htaccess-on-apache/
Don't overcomplicate things with unnecessary mod_rewrite. Just use DirectoryIndex index.html.

Not having `.html` in Website URL?

How is it possible to have a url of a basic website, not include the .html at the end of a webpage?
My website is just a few pages, but I don't like having the .html in my link: www.mywebsite.com/mypage.html
If I type: www.mywebsite.com/mypage, of course, it's not found :(
I navigate around my site just using typical hyperlinks.
Probably a dumb question, but I've googled it and the stuff I find is way more complex than just html code and is usually referring to php or perl.
Thanks.
You sinply make an .htaccess file and put the following in it:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
What web server software are you using? If Apache, you will likely be interested in the rewrite mod.
Something like the following:
RewriteRule ^mypage/?$ mypage.html [NC,L]
In your .htaccess file. I believe you need to enable the mod first too.
Simple solution is to change the name of your website from mypage.html to mypage

htaccess redirection for html files and other links

I was in the need of migrating my site to a subfolder, it is a php script, its links are like this :
aff_link.php?id=812 (number changes at the end)
and html files like
gifts.html
rss_feeds.html
and others ending in .html
I need to redirect those two kind of links to a subfolder called "old"
any advice on this?
Thank you in advance.
You can use this rule in site root .htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)q=id=\d+ [NC]
RewriteRule ^aff_link\.php$ /old/$0 [L,NC,R=301,NE]

.htaccess and DirectoryIndex

I have a two files in my root folder: main.html and index.php.
Well, normally index.php takes places as it has higher priority to respond, just wanted to change the logic, so then at first the user has to visit the main.html and then get redirected to index.php. I tried the below code in my .htaccess but it doesn't work as I expected. Actually after doing that, now the first page is correctly changed to main.html, but it never get redirected to index.php!!! It actually returns to main.html again and again (like loop!)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
DirectoryIndex main.html /main.html
ps:
1- even if i try to request the index.php it will open main.html instead!
You can change the default page for directory using the following in your htaccess file, as you have done in the question. Users would land on main.html (instead of index.php) when navigating to "www.coolsite.com/".
//Change default directory page
DirectoryIndex main.html
To redirect the user to another page, you can use the following:
window.location = "http://www.coolsite.com/index.php";
Well, it seems wordpress and static content [index page!] does not not come along! (mostly because of the existing RewriteRule[s] + WP internals)
The workaround is to create a 'page template' (the static content you wish to display as index page) and ask WP to display it as Front-page .

Change root folder on HTML links

I have a bunch of HTML files with link tags like this:
[...]
Link 1
Link 2
Link 3
[...]
The website is inside a folder on the server, e.g. http://www.website.com/folder/, but links beggining with / point to the root, e.g. http://www.website.com/, but the files file1.php, file2.php, file3.php, etc. are inside the folder.
How would I be able to make the links act as if the root folder were the folder where they are, without changing HTML contents?
You can try with a internal redirect like this:
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule ^(.*)$ /folder/$1 [L,QSA]
The condition is to redirect only PHP files to the folder, if that gives you a loop you can go with a more specific one:
RewriteRule ^(.*)\.php$ /folder/$1.php [L,QSA]
With RewriteBase something like this:
RewriteBase /folder/
RewriteRule ^(.*)\.php$ $1.php [L,QSA]