Streaming live at 10am (PST)

Clean URL .htaccess with dashes


#1

Hi wondering if someone could help. I’m sure this is a simple thing. I am still learning :grinning:

I made a .htaccss file to rewrite urls to not include .html

It works great until it is a url with a dash in it (ex. website.com/privacy-policy)

Webflow creates these slugs with a dash by default. If I change them to one word without a dash it works. If it has a dash, causes a 404 error. I would prefer to keep the dashes.

What changes to .htaccess file I created do I need to make to allow dashes?

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /. index\ HTTP/
RewriteRule ^(.
)index$ http://YOURWEBSITE.COM/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://YOURWEBSITE.COM/$1 [L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+).html\ HTTP/
RewriteRule ^(.+).html$ http://YOURWEBSITE.COM/1 [L,R=301] RewriteRule ^([a-z]+) /$1.html [L]


#2

Here is the solution to anyone having same problem:

Need to broaden regex to include more characters. ([\w-]+) includes letters, numbers and dashes.

So this is what you want in htaccess:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /. index\ HTTP/
RewriteRule ^(.
)index$ http://YOURWEBSITE.COM/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://YOURWEBSITE.COM/$1 [L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+).html\ HTTP/
RewriteRule ^(.+).html$ http://YOURWEBSITE.COM/1 [L,R=301] RewriteRule ^([\w-]+) /$1.html [L]