Put this in the /foo/bar/
folder's htaccess file:
RewriteEngine On
RewriteRule ^(?:[^/]+/|)([^/.]+)\.htm$ details.php?id=$1 [L,QSA]
Question
I have a bunch of pages that need static URL paths, for example:
foo/bar/fooey/qwertyuiop.htm
However, these pages don't exist. They are all the same except with slightly different variables.
So I created /foo/bar/details.php
, which takes the parameters "id" and "type".
Any ideas how I can make a Rewrite rule that redirects all .htms in /foo and it's subdirectories to details.php, like this:
/foo/bar/fooey/abc123.htm --> /foo/bar/details.php?id=abc123
/foo/bar/xyzzy/hellothere.htm --> /foo/bar/details.php?id=hellothere
and
/foo/bar/applepie/check_pie_status.htm?type=peach
would be rewritten to
/foo/bar/details.php?id=check_pie_status&type=peach
In other words, any requested .htm would be rewritten to that PHP file, without the client seeing it.
Solution
Put this in the /foo/bar/
folder's htaccess file:
RewriteEngine On
RewriteRule ^(?:[^/]+/|)([^/.]+)\.htm$ details.php?id=$1 [L,QSA]
OTHER TIPS
Using .htaccess
RewriteEngine On
RewriteRule ^(.*)\.html$ details.php?id=$1&%{QUERY_STRING} [L]
put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+/[^/]+)/.*?/([^/.]+)\.htm$ $1/details.php?id=$2 [L,QSA,NC]
its sounds like a landing page issue..
from my experience i can offer those ideas:
create a different folder path using Nginx sites-enable folder at /etc/site-enable. this will allow to attach a certain domain to a folders path or to create a general rule that will send any /foo to a certein path.
create script that loads a specific folder for every domain. i think that a DB using domain as a key with a path txt is the best solution.. this is a bit of system design issue.
calling to the path using Reg-ex at your main index php file extracting this data from $_SERVER URI..