How to show index of page with htaccess? - html

I'm new to hosting and I'm trying to get a basic "index of" page to show.
I have an address ie: www.mydomain.com/files
I just have some zip files in that location that I'd like to show and allow users to download but not sure how to do this. At the moment I just get a FORBIDDEN page.

Create an .htaccess file and put
Options +Indexes
In it.

try this :
Rewritecond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Related

How to redirect index.html to /

How can I redirect every index.html file to /
For example redirect this URL: https://www.example.com/contact/index.html to https://www.example.com/contact/
Note: I don't want to redirect to the root, I want to redirect to the same directory just remove the index.html
Thank you in advance for your time
Assuming you are using Apache the following lines in .htaccess file under the /contact folder will do the trick:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/index.html$ %{CONTEXT_PREFIX}/folder/$1/ [R=301,L]
RewriteRule ^index.html$ %{CONTEXT_PREFIX}/folder/ [R=301,L]
where folder is contact in your example.
Earlier I suggested using the following rule for a shortcut of the above two:
RewriteRule ^(.*)index.html$ %{CONTEXT_PREFIX}/folder/$1 [R=301,L]
However, this has an unwanted side-effect of redirecting say something like https://www.example.com/contact/myindex.html to https://www.example.com/contact/my
Note: Please be careful not to cause redirection "loops" like:
xxx/index.html -> xxx/ -> xxx/index.html -> xxx/ ...

send id via url but hidden

I have an html link:
Link
I formatted the link destination with a htaccess file:
RewriteRule ^destination$ index.php?content=destination [L,NC,QSA]
The question is: How can I give a ID via URL to the destination?
the full link will be index.php?content=destination?ID=x
X will be a dynamic number
but I would like to show this in the url - it should be invisible.
But I don't know how I have to modify the rewriteRule to realize it.
Although not a pretty solution and it obviously comes with flaws, you could always use cookies.
set a cookie in PHP:
setcookie("page_id","987987");
and look for it in htaccess
RewriteCond %{HTTP_COOKIE} ^page_id=([0-9]*)$ [NC]
RewriteRule ^destination$ index.php?content=destination&id=%1 [L,NC,QSA]

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]

HTML Place in folder while not placing it in the site directory? [duplicate]

My aim is:
domain.com/folder
rewrite ->
domain.com
this shall concern ALL links inside that site.
I mean on the site are links like:
domain.com/folder/forum.html
domain.com/folder/community.html
etc.
This is my aim:
domain.com/forum.html
domain.com/community.html
etc.
and its very important that the "folder" is never in the url in the adressbar visible.
I tried already many codes but I couldnt really solve this problem.
My best try was with this code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)folder
RewriteRule ^(.*)$ folder/$1 [L]
If I enter
domain.com
I get the content of
domain.com/folder
displayed, what is correct ("folder" is not in the url shown). But when i click on some links of the site like: domain.com/folder/community.html then I can see again "folder" in the url, but I want that it becomes ALWAYS removed.
here is my site:
thewedgiecommunity.x10.mx/wedgiecommunity/
My aim is to remove the "wedgiecommunity" (=folder)
This link is working
thewedgiecommunity.x10.mx/
But when you click on Community (
thewedgiecommunity.x10.mx/wedgiecommunity/community.html
) then i get again "wedgiecommunity" in the URL.
Would be awesome when someone could help me
You can use this code:
Goes in DOCUMENT_ROOT/wedgiecommunity/.htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+wedgiecommunity([^\s]*) [NC]
RewriteRule ^ %1 [R=301,L]
Goes in DOCUMENT_ROOT/.htaccess:
RewriteEngine On
RewriteRule !^/?wedgiecommunity wedgiecommunity%{REQUEST_URI} [L,NC]
You can use this rule to "remove" the folder from the URL when it is accessed directly via the browser:
RewriteCond %{THE_REQUEST} \ /wedgiecommunity/
RewriteRule ^wedgiecommunity/(.*)$ /$1 [L,R=301]
Then your other rule will handle the rest.

Link to index page of website

Is there a way to link to the index page of a website without specifying the name of the index page or the full website URL?
I have this:
Home
But when I click the link, my address bar shows:
mydomain.com/index.html
I would like it to show:
mydomain.com
Can I do that without putting the full URL (mydomain.com) in the href? If so, how?
For future viewers, I also found this question helpful.
You can just do this:
Home
Any href preceded by a slash is relative the root directory.
It should be noted that when viewing a webpage from a local hard drive in a browser, this will cause the link not to function.
I know this post is old and has an answer. But here is my contribution that also supports index that is not exactly in the root directory
to goto
mydomain.com/index.html
without index.html showing in address bar
Home
this will always point to mydomain.com no matter where the directory your file was saved to.
to point to the index in a directory use this:
Home
this will point to mydomain.com/subdir for mydomain.com/subdir/index.html while the accepted answer will always point to mydomain.com (and this is not always the desired action)
Create a ".htaccess" file and upload to your host public folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.yourwebsite.com.ph/ [R=301,L]
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
</IfModule>