Reputation: 1263
I am creating a CMS where the styles and formatting for a given page are dynamically generated depending on the type of page (general, member, download,etc.). In the past I have used the following .htaccess to identify the page type:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^general/(.*)$ general.php?title=$1 [QSA,L]
which works fine but required me to create a rendering page for each page type... general.php, member.php, download.php, etc.
WHAT I AM TRYING TO DO IS...
Through .htaccess have a wild card to identify the page type to have all pages render from a single [page.php] file so that the page types can be created on the fly without have to create a rendering page for each page type.
I am having an issue with a $ sign showing up in my results. I only know enough about .htaccess to be dangerous.
THIS IS MY TEST PHP
<?php
$type = $_REQUEST['type'];
$title = $_REQUEST['title'];
echo $type.'<br>'.$title;
?>
THIS URL:
http://my-site.com/general/this-is-a-general-page
WITH THE .HTACCESS REWRITE RULE SET AS:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/(.*)$ temp.php?type=$1$&title=$2 [QSA,L]
PRODUCES:
general$
this-is-a-general-page
I can't figure out why the $ is at the end of the page type. I have also tried removing the $:
RewriteRule ^(.*)/(.*) temp.php?type=$1$&title=$2 [QSA,L]
but am getting the same result.
Upvotes: 1
Views: 36
Reputation: 784908
You can use:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/([^/]+)/?$ temp.php?type=$1&title=$2 [QSA,L]
You had a stray $
after $1
in your rule.
PS: I have also tweaked your regex a little to make it more efficient.
Upvotes: 1