subfolder and html page name is the same and nor working - html

I have a webpage, which has got a html page called "blog.html" and a subfolder which is called "blog" and have some other html page inside. I just removed .html with htaccess.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Now, when somebody click on the "blog" menu, the following happened:
You don't have permission to access /blog/.html on this server.
I wonder how can i fix this, i would like to have a page with working urls like this:
mydomain.com
mydomain.com/blog
mydomain.com/blog/first_post

Change your rule to this:
DirectorySlash Off
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=302]
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
RewriteRule ^(.+?)/?$ $1.html [L]
And test it in a different browser.

Related

How to allow a html file to be displayed on a website in htaccess

i've never really played around with htaccess before and can't figure out how I would go about displaying a html file in a folder called "radio" when someone was to go to mydomain/radio. The current code in htaccess is below and came with my website cms when I set it up. Any help is appreciated.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([^.]+)\.(png|jpg|gif|css|js|otf|ico) [NC]
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) public/$1 [L]
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^ public/index.php [QSA,L]

Website links won't work with .htaccess code which removes .html extension

I have the following code in my .htacess file for my website to remove '.html' from my urls and to redirect any .html to the same page without it (example.com/home.html to example.com/home)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
However, when I try to click on links that are pointed to other pages on my website, I get a 404 error.
I've tried setting the href to http://www.example.com/page2, /page2 and more but I still get the same error. Any help?
Please save your code and put only the following code in your main directory .htaccess file :
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(.*?)\.html[\s?/] [NC]
RewriteRule (.*)$ /%1%2 [R=302,L,NE]
Note: clear your browser cache because you did 301 redirect and test the code

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?
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]

.htaccess: remove .html and redirect slash version

On my site, all pages have .html extension and are directly off the root (i.e., site.com/page.html). I've successfully used the following .htaccess code to make .html not show:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
This gives me a url like site.com/page, but in the event that a user links to or visits the url using a slash (i.e., site.com/page/), I'd like to 301 redirect to the non-slash version.
I'm having trouble integrating this part into the above code. Thanks in advance for any suggestions.
Try to something like this
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]

redirect subfolder to root with <subfolder-name>.html using htaccess

I have website that has links like
domain-name.com/pages/contact-us/
www.domain-name.com/pages/contact-us/
domain-name.com/pages/about-us/
www.domain-name.com/pages/about-us/
and other pages ...
What I'm looking for how i can redirect them permanently to same subfoldername.html using htaccess . for example for all the links above should redirected to
domain-name.com/contact-us.html
www.domain-name.com/contact-us.html
domain-name.com/about-us.html
www.domain-name.com/about-us.html
also for other pages, otherwise if page not found to root index.html .
Thanks in advance.
Try the following
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(/pages/(.*[^/])/?)$
RewriteRule ^(.*)$ /%2.html [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.html [L,R=302]
The first three lines will remove the folder pages. If there is a trailing slash, it will be removed. The last three lines will redirect to /index.html, if the request file does not exist.