Search code examples
phpurlcontent-management-systempermalinks

how rewrite urls without rooting to single file?


i guess is not possible but it may exist a way that i don't know for pretty url, or url rewriting without rooting all requests on a single index.php page

on existing website with folder structure and url like

http://www.mywebsite.com/news/?id=123

is it possible to transform them in something like

http://www.mywebsite.com/news/myarticle

i can't find any solution to solve this without rewrite the code to root all request to a single index.php


Solution

  • But you are already use index.php for all news: /news/index.php.

    You can use for it standart .htaccess trick

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

    And put it to /news/.htaccess. Every request on /news/*** will lead to /news/index.php, but other folders will keep they behaviour.