Howard Zoopaloopa
Howard Zoopaloopa

Reputation: 3822

Reroute Traffic to PHP Script From Specific Folder

I'm basically trying to build a tiny router that would take any traffic from "mysite.com/news/article_01" and reroute that to a script living in the root "html" folder called "news.php" where I'd capture the article name as a variable and deliver content from there.

The trick is I don't want to overwrite the current index.html file.

I found this little snippet:

Options +FollowSymLinks
RewriteEngine On
 
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
 
RewriteRule ^.*$ ./index.php

I have a feeling though that that would route ALL traffic to the php file which I don't want...

Thoughts?

Upvotes: 1

Views: 41

Answers (1)

anubhava
anubhava

Reputation: 785651

It appears for your requirement you may be able to use this more targeted rule:

Options +FollowSymLinks
RewriteEngine On
 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^news/ index.php [L,NC]

This will only route /news/ URIs to index.php instead of everything.

Upvotes: 2

Related Questions