Changing url of html pages - html

I am trying to change the url of my html page to as below
example.com/intraday.html to example.com/intraday.
example.com/economic_calendar.html to example.com/economiccalendar
I am trying it using .htaccess file but it is not working
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /([^\ ]+)\.html
RewriteRule ^ /%2/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.html -f
RewriteRule ^ /%1.html [L]
Any suggestion.

https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^/]+)/?$ $1.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)([^/]+)/?$ $1_$2.html [L]

Related

How do I remove the .html from the end of URL while using SiteGround

I had originally built my website in React before learning that my client is using SiteGround so I had to change everything over to a basic HTML format. I have my navbar using href = "fileName.html" to navigate the page. This leads the URL to become www."siteName".com/"fileName.html" once navigating off the homepage.
This is what I have so far in my .htaccess to remove the .html from the end:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
This does not seem to be working. Should I change my .htaccess file? Should I change the way my navbar navigates the pages?
With your shown samples/attempts, please try following .htaccess Rules file. Please make sure to clear your browser cache before testing your URLs.
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine ON
RewriteBase /
###Rules for handling .html to without html uri in browser.
RewriteCond %{REQUEST_URI} \s/([^.]*)\.html\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
RewriteRule ^(.*)/?$ $1.html [L]
##Rule from OP's already existing .htaccess file.
RewriteRule ^index\.html$ - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>

Removing .html extension from website

<center><button onclick="window.location.href='/shop.html'">SHOP</button></center>
I am trying to remove the .html tag from /shop.html. I have created a .htaccess file inside of my root folder. I included the follow inside;
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
I then removed the .html from /shop.html and had no luck with error 404.
Cheers, Ben.
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]
If the requested URL does not have an extension:
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
And it is not a directory:
RewriteCond %{REQUEST_FILENAME} !-d
And it is not a file:
RewriteCond %{REQUEST_FILENAME} !-f
And if by adding .html we find a file:
RewriteCond %{REQUEST_FILENAME}.html -f
Then add .html and serve that file:
RewriteRule (.*) $1.html [L]

RewriteRule .htaccess not working multiple

I have changed my .htaccess to make nice url.
What's wrong in this?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/]+).html$ article.php?url=$1 [NC,L]
RewriteRule ^([a-zA-Z0-9-/]+).html/$ article.php?url=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/([a-zA-Z0-9-/]+).html$ category.php?cat=$1 [NC,L]
RewriteRule ^category/([a-zA-Z0-9-/]+).html/$ category.php?cat=$1 [NC,L]
and I got from this
.htaccess rewriteRule conflict
I would to make like this
localhost/category/bla.html
localhost/seo/bla.html
and this is the url in database
bla.html
seo/bla-bla.html
just just move the bottom part up
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/([a-zA-Z0-9-/]+).html$ category.php?cat=$1 [QSA,L]
RewriteRule ^category/([a-zA-Z0-9-/]+).html/$ category.php?cat=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/]+).html$ article.php?url=$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9-/]+).html/$ article.php?url=$1 [L,QSA]

Remove .html from url in apache2

I am trying to remove .html
so the site is www.example.com/login
login.html is located in /var/www/html/login.html
I created .htaccess in /var/www/html/.htaccess
And I put in:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
This doesn't seem to work. Can someone tell me what is wrong?
Try it this way.
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ $1.html [L]
Apparently you changed your question.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

Exclude all Files from Rewrite (NGINX to APACHE Migration)

My URL structure is like
http://www.example.com/folder/index.php?dir=dir1
To be able to access it from
http://www.example.com/folder/dir1
and at the same time redirect the 1st URL to 2nd one, my htaccess (in 'folder') is
Options +FollowSymLinks
RewriteEngine On
RewriteBase /folder
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteCond %{QUERY_STRING} ^dir=(.*)$ [NC]
RewriteRule ^ %1? [L,R=301,NE]
RewriteRule ^(.+)/? index.php?dir=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ index.php?dir=$1 [L,QSA]
The Redirect and Rewrite were working perfect until recently I switched from NGINX back to APACHE.The trouble is that it is now also rewriting file extensions which I don't want!How can I only apply it only to directories and exclude ALL files from it?
Figured it out! :)
Actually had to add
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d
before the first rewrite!
So the htaccess looks like:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /folder
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteCond %{QUERY_STRING} ^dir=(.*)$ [NC]
RewriteRule ^ %1? [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)/? index.php?dir=$1 [L,QSA]