2

I have following rewriterules:

RewriteEngine On

RewriteRule ^([^\-]*)-(.*)-von-(.*)\.html$ $1index.php?filter=$2&marke=$3 [QSA]
RewriteRule ^([^\-]*)-von-(.*)\.html$ $1index.php?marke=$2 [QSA]
RewriteRule ^([^\-]*)-(.*)\.html$ $1index.php?filter=$2 [QSA]

RewriteRule ^(.*)\.html$ $1index.php

The first 3 rules are working, but the fourth, just rewrite index.php to .html is not. What is wrong here?

EDIT:

The URL is example.com/folder/subfolder/index.php

In the folder I got following htaccess:

RewriteEngine on
RewriteRule ^subfolder(.*) subfolder/$1

And the htaccess in subfolder is the one above

Now the URL for the first rule is example.com/folder/subfolder-value1-von-value2.html and works, for the second and third rule it's example.com/folder/subfolder-value1.html and example.com/folder/subfolder-von-value2.html So with logic the fourth rule should also work just without the parameters but it's not working

12
  • Your 4th rule will rewrite index.html to /indexindex.php which doesn't make any sense. Clarify with examples what you're trying to do. Commented Apr 30, 2014 at 7:15
  • Allright I'll edit my post then you will see more Commented Apr 30, 2014 at 7:24
  • With RewriteRule ^(.*)html$ $1index.php so without the dot example.com/folder/subfolderhtml it works but I need the dot -.- Commented Apr 30, 2014 at 7:41
  • With 4th rule example.com/folder/subfolder-value1-von-value2.html will be rewritten to example.com/folder/subfolder/value1-von-value2index.php which will give you 404 since value1-von-value2index.php won't exist in subfolder. Commented Apr 30, 2014 at 7:46
  • But it's not because I get value1 and value2 correctly it goes to mysql_query and I get stuff associated with these values. I only get the forbidden error with fourth rule: example.com/folder/subfolder.html Commented Apr 30, 2014 at 7:55

3 Answers 3

1

Place this in /folder/.htaccess:

RewriteEngine on

RewriteRule ^subfolder\.html$ subfolder/index.php [L,NC]

RewriteRule ^subfolder(.+) subfolder/$1 [L,NC]
Sign up to request clarification or add additional context in comments.

4 Comments

omg it WORKS THANK YOU =) hours of struggle are finally over :)
I have only one more question, what would be the rule when the subfolder name is subfolder-two so with a hyphen? I need a rule which works with and without hyphen
I am on mobile at present. I will update the rule in couple of hours.
That rule will be: RewriteRule ^(subfolder-two)\.html$ $1/index.php [L,NC]
1

You shouldn't add $1 to the second part of the rule.it'll append the first matching group to the index.php file name. what you are currently getting is 'indexindex.php'

if you just want to rewrite index.html to index.php then you can place following line at the end of the file.

RewriteRule ^index.html$ index.php [L,NC]

also you might wanna remove $1 part from other lines as well.

3 Comments

no I don't want index.php to be index.html but just .html. I changed rewriterules for the folders where the index.php files are included so they work without / at the end and I get urls like example.com/folder-value1-von-value2.html it all works fine just not example.com/folder.html, so the last rule. It's not working when I leave $1 at any of the rules, also the fourth
@EddyUnruh As i said on my post, $1index.php translate to example.com/folderindex.php do you have a such file ? if you want to redirect example.com/folder.html to exampl.com/folder then you can use RewriteRule ^(.*)\.html$ $1
Thats right it translates to example.com/folderindex.php and example.com/folderindex.php translates to example.com/folder/index.php because of the rules in root of the domain. It all works fine except the fourth rule, I just need to rewrite index.php to .html I don't know why it's working when parameters are set and not without
0

Can you try this & see ?

RewriteEngine on
RewriteRule ^(.*)\.html $1\.php 

4 Comments

It makes index.php to index.html and works but I need index.php to just .html
what do u mean by just .html. It means it can be abc.html or bcd.html ? In that case u need to do it like this - RewriteRule ^abc\.html index\.php
no it means just .html and nothing before it because I allready use the folder name as category name
I guess it's impossible when nothing comes before .html?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.