July 28, 201214 yr I would like my site to be .com/username but I also want my pages to be .com/signup I know that I could make it .com/user/username but I would prefer if I could use the first method, what would I need to do to make exceptions, this is what I have so far... Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^([a-z0-9_.]+)*$ profile.php?username=$1 [NC] At the moment it is taking any /anything and redirecting to profile.php Edited July 28, 201214 yr by adamsmith
July 28, 201214 yr You're basically going to have to put a "router" between the /xyz and your destination page. In the router you need to get the string, check if it's a page. If it is, display that. If it's not you'd show the profile page. The router simply needs to include the relevant .php file
July 28, 201214 yr Author You're basically going to have to put a "router" between the /xyz and your destination page. In the router you need to get the string, check if it's a page. If it is, display that. If it's not you'd show the profile page. The router simply needs to include the relevant .php file How would I go about doing that in the .htaccess file? Is it worth it or will that add (significant) load time to each page?
July 29, 201214 yr Author I do keep meaning to learn codeignighter but I just always find myself writing out from scratch and think I'll just change it later, but I never do.
July 31, 201214 yr <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ app.php [QSA,L] </IfModule> SetEnv APPLICATION_ENV development <?php require_once __DIR__.'/../app/AppKernel.php'; define('ROOT_DIR',realpath(realpath(__DIR__.'/..'))); $app = new Kernel(); $app->dispacheRequest(); public function dispacheRequest() { $this->getMethodRoute('homepage'); $match = false; foreach($this->routes as $route) { if (!isset($route['pattern'])) { continue; } if (preg_match('/'.$route['pattern'].'/', $_SERVER['REQUEST_URI']) >0) { if (isset($route['headers'])) { foreach($route['headers'] as $header) { header($header); } } if (isset($route['include'])) { include ROOT_DIR.DIRECTORY_SEPARATOR.$route['include']; } $match = true; } } if (!$match) { header($this->routes['404']['headers'][0]); include ROOT_DIR.DIRECTORY_SEPARATOR.$this->routes['404']['include']; } } Try something like that? They are just snippets from a little framework I have started..
Create an account or sign in to comment