Htaccess doesn't seem to work

epiz_31399175

i have an htaccess file in htdocs with the following

RewriteEngine On
RewriteRule ^(.+)$ /index.html?planta=$1 [L,R=301]

objective is that so when i go to
plantas.epizy.com/example
i get redirected to
plantas.epizy.com/index.html?planta=example

however i get redirected to a 404 error page

i’m new to htaccess and infinityfree so i can’t figure out what i’m doing wrong

It seems like you want to rewrite a query string as a path. A quick Google search brings me to this:

@wackyblackie
i’m still confused about how it works but i changed it to this

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*?)/?$ /index.html?planta=$1 [L]

using the example in the link you showed
and i’m still getting the same problem
going to plantas.epizy.com/test leads me to a 404 error page
i honestly don’t think the problem is in the code, everything seems to be typed correctly and makes sense, but somehow doesn’t work
i could be wrong tough

U can use a 301 redirect.

@jaikrishna.t
I did, nothing changes, still 404.

Try

RewriteEngine On
RewriteRule ^/?([0-9]+)/?$ /index.html?planta=$1 [L]

More solutions outlined here:
https://cwiki.apache.org/confluence/display/httpd/RewritePathInfo#RewritePathInfo-Movingpathinformationtoaquerystring-simple

1 Like

@wackyblackie
None of them seem to work, in any way
Just tried 3 different solutions from there, all of them lead to a 404 page
That’s why i don’t think the problem is in the code
I might be doing something else wrong
Also i’ve tried this earlier in the day and it did seem to work sometimes
Just now it doesn’t anymore

Just to confirm, is the .htaccess in the htdocs folder?

1 Like

So, Do you want to use example.com/page instead of example.com/page.html ?

If Yes

1.Write your code in any code editor (VSC)
2.Create a file in Infinity Free as example (don’t include the html version)
3.Paste the Code in the File
4.Your Page is Live

This will work with HTML, CSS, JS, PHP

Sorry if I was wrong !

Judging by your desired situation, then from the top of my head, I think this is the .htaccess code you need:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.html?planta=$1 [L,R=301]

So your original code seems like a good solution.

I checked your account and I think I see why your previous code gave a 404 error: the code is placed in a file called htaccess, but it should be called .htaccess. The dot at the start is really important, and the file needs to be named exactly that or it won’t be picked up.

6 Likes

Thank you admin, that fixed it!
I didn’t notice the dot was missing
Now it works how i wanted :smiley:

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.