1

I want to redirect the URL http://example.com/sub-folder/filename.html to http://example.com/sub-folder/index.php?p=filename.html

I already have the following:

    <IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /
    #RewriteRule ^stedentrip-naar/([a-zA-Z0-9_-]+)\.html$  stedentrip-naar/index.php?p=$1 [L,NC,QSA]
    RewriteRule ^stedentrip-naar/(.*)$ /stedentrip-naar/$1 [R=301,NC,L]
    </IfModule>
4
  • 1
    So what's wrong? What's the question?
    – Mimi
    Feb 27, 2014 at 18:21
  • I get an 404 not found on the page
    – Benidorm
    Feb 27, 2014 at 18:22
  • Check out your apache error logs. They will have more information about the request that might point you in a better direction. Also, I could be wrong, but it appears you are redirecting anything that falls under a directory to that same directory. Does the /stedentrip-naar/ directory even exist? Feb 27, 2014 at 18:28
  • No, my .htaccess file exists in the root of the public_html. The /stedentrip-naar/ does exist.
    – Benidorm
    Feb 27, 2014 at 18:31

2 Answers 2

1

Place this rule in your /sub-folder/.htaccess:

RewriteEngine on
RewriteBase /stedentrip-naar/

RewriteRule ^([\w-]+\.html)$ index.php?p=$1 [L,QSA,NC]
6
  • I'm keep getting a white screen now, is it the [L,QSA,NC] at the end of the line that causes this?
    – Benidorm
    Feb 27, 2014 at 19:37
  • THat should not be causing it. You can open your page in Firebug and see if there is any 404 for image/css/js files?
    – anubhava
    Feb 27, 2014 at 19:39
  • Strange, no errors at all, I get a 200 page ok in my network tab and my php error reporting is on.
    – Benidorm
    Feb 27, 2014 at 19:44
  • And if you open /stedentrip-naar/index.php?p=filename.html does it work?
    – anubhava
    Feb 27, 2014 at 19:46
  • 1
    Its not working either, so the htaccess is fine. I will search for a solution. Thanks again.
    – Benidorm
    Feb 27, 2014 at 19:53
0

Try this:

RewriteEngine on 
RewriteRule ^sub-folder/([a-zA-Z0-9_-]+)\.html$ sub-folder/index.php?p=$1.html
1
  • Thanks for your answer, I think something like this is the solution but this doesnt work. I still got the 404 error. I tried it like this. RewriteRule ^stedentrip-naar/([a-zA-Z0-9_-]+)\.html$ stedentrip-naar/index.php?p=$1
    – Benidorm
    Feb 27, 2014 at 19:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.