Search code examples
htmlapachemod-rewritestatic-linkingsubdirectory

Links (without /index in them) are not pointing to index of that subdirectory


I've looked for about two hours for a way of solving, this to no avail:

Just to make it easier I'm providing links: malumkose.com malumkose.com/hizmetler

In the main page (first link) there is a button link to the page "hizmetler."

When I was linking these pages to one another, I didn't add in the /index or /index.html extensions to the links, and thought it would work on the server as it did on localhost.

The thing is, my site is peppered with these links - they're all over the joint! I would go and manually change these to add the file extension, but that would only cause the link to direct me to "hizmetler/index" instead of just "hizmetler."

I have tried adding the first line here to my .htaccess file, but it still doesn't point links without index in them, to the indexes of these subdirectories.

`DirectoryIndex index.html
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]`

How could I possibly kill these two birds with one stone?


Solution

  • I don't completely understand the structure for the files of your pages, but this should help for your .htaccess file:

    Options +FollowSymLinks
    RewriteEngine On
    DirectoryIndex index.html
    
    RewriteRule ^hizmetler$ ./hizmetler/index.html
    RewriteRule ^something$ ./something/index.html
    RewriteRule ^something-else$ ./something-else/index.html
    

    Then it will work as follow:

    • malumkose.com/ > /index.html
    • malumkose.com/hizmetler > /hizmetler/index.html
    • malumkose.com/something > /something/index.html
    • malumkose.com/something-esle > /something-else/index.html

    If you want to force SSL/HTTPS, then add (between the enter of the above script):

    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]