4

I am new to htaccess files, and I understand how to do basic rewrites of URLs such as removing index.php, extensions, etc. I am also able to use $_SERVER["PATH_INFO"] to work with anything trailing the file.

What I struggle with is how it would be possible to do this with a trailing faux-directory structure on another file other than the (not-shown) index.php. Lets say I have

domain.com/render.php/this

and I want it to read

domain.com/render/this

My workaround is currently to do all my logic in my index.php file, but I would like to break it up into several files, so that I would have index.php doing my home-page stuff, and render.php something completely different.

Thank you for you time.

justMoritz
  • 83
  • 6
  • 1
    Can't test it right now, and I am not all that familiar with PI, but doesn't do `RewriteRule ^([^./]+)/(.*)$ $1.php/$2 [L]` do the job? You might need to use the `DPI` flag. – Sumurai8 Jul 03 '16 at 16:43
  • thanks for the eventual upvote+accept! +1 goes to you! – cnst Jul 24 '16 at 15:22

1 Answers1

1

It depends on your overall directory structure. Take a look at Apache .htaccess to hide both .php and .html extentions, for example.

If you already have /render/this configured to go to /render.php/this, and all you have to do is perform redirection the other way, then try this:

RewriteEngine   On
RewriteCond %{REQUEST_URI}  \b\.php\b
RewriteRule ^([^/.])\.php/(.*)$ $1/$2   [R]

(The \b part matches at a word boundary, as per pcrepattern(3), which is from the pcre library that both Apache httpd as well as nginx use in support of regular expressions.)

Community
  • 1
  • 1
cnst
  • 25,870
  • 6
  • 90
  • 122
  • heh, i think there is a typo in my regex above -- `([^/.])` should probably be `([^/.]+)`. – cnst Jul 24 '16 at 15:19