Forum Moderators: phranque
RewriteEngine On
RewriteBase /
RewriteRule .* index2.php
<?php
echo "hiiii";
class Foo {
static public function test($classname)
{
if(preg_match('/\\\\/', $classname))
{
$path = str_replace('\\', '/', $classname);
}
else
{
$path = str_replace('_', '/', $classname);
}
if (is_readable($path.".php"))
{
require_once $path .".php";
}
}
}
spl_autoload_register('\Foo::test');
\controller\Controller::run();
?>
RewriteEngine On
RewriteBase /
This is garbage
RewriteRule .* index2.php
RewriteEngine On
Options FollowSymLinks
RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|png|gif|swf)$ [NC]
RewriteRule ^([^/]+)/?([^/]+)?/?([^/]+)?/? index2.php?cmd=$1&action=$2&ajax=$3 [L,QSA]
[edited by: g1smd at 7:39 pm (utc) on Feb 7, 2012]
By allowing an optional trailing slash you allow two URLs to be valid for every piece of content. That's a Duplicate Content issue. Redirect "with slash" to "without" and rewrite only the "without slash" requests.
RewriteCond {REQUEST_URI} !-f to any of your code. That is one of the most massively inefficient ways to do things. You can do this with RegEx patterns alone. [edited by: g1smd at 8:00 pm (utc) on Feb 7, 2012]
Yes, but you need to filter what the front controller "sees" in terms of URL requests. Requests for robots.txt, searchengine verification files, and so on, should be handled by "real" files.
RewriteEngine On
Options FollowSymLinks
RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|png|gif|swf)$ [NC]
RewriteRule ^([^/]+)$ index2.php?cmd=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)$ index2.php?cmd=$1&action=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index2.php?cmd=$1&action=$2&ajax=$3 [L,QSA]
RewriteEngine On
Options FollowSymLinks
RewriteRule ^([^/.]+)$ index2.php?cmd=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/.]+)$ index2.php?cmd=$1&action=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)$ index2.php?cmd=$1&action=$2&ajax=$3 [L,QSA]
RewriteEngine On
Options FollowSymLinks
RewriteCond %{THE_REQUEST} (/) [NC]
RewriteRule /$ $1 [L,QSA]
RewriteRule ^([^/.]+)$ index.php?cmd=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2&ajax=$3 [L,QSA]
GET /somepath HTTP/1.1 %{THE_REQUEST} ^[A-Z]{3,9}\ /somestuff/ HTTP/ ^([^/]+/)*([^/.]+)/$ which is slightly different to your other patterns. Do NOT use (.*) here.
RewriteEngine On
Options FollowSymLinks
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/\ HTTP/
RewriteRule ^(([^/]+/)*([^/.]+))/$ $1 [R]
RewriteRule ^([^/.]+)$ index.php?cmd=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2&ajax=$3 [L,QSA]
RewriteRule ^(([^/]+/)*([^/.]+))/$ $1 [R]
Alternatively if you use only the .html extension in your page URLs you could build that into the RewriteRule pattern by ending them with ([^/.]+)\.html$ for the final part of each rule pattern and completely remove the RewriteCond from each rule too.
RewriteEngine On
Options FollowSymLinks
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/\ HTTP/
RewriteRule ^(([^/]+/)*([^/.]+))/$ $1 [R=301,L]
RewriteRule ^([^/.]+)$ index.php?cmd=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2&ajax=$3 [L,QSA]
RewriteCond %{REQUEST_URI} !-d condition on this to ensure that requests for real folders are not redirected. [edited by: g1smd at 2:33 am (utc) on Feb 8, 2012]
You might need an extra RewriteCond %{REQUEST_URI} !-d condition on this to ensure that requests for real folders are not redirected.
RewriteEngine On
Options FollowSymLinks
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))/\ HTTP/
RewriteRule ^(myProject/([^/]+/)*([^/.]+))/$ $1 [R=301,L]
RewriteRule ^([^/.]+)$ index.php?cmd=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2&ajax=$3 [L,QSA]
You keep forgetting to add the full protocol and domain name to the rewrite:
RewriteRule ^(myProject/([^/]+/)*([^/.]+))/$ http://www.example.com/$1 [R=301,L]
RewriteEngine On
Options FollowSymLinks
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))/\ HTTP/
RewriteRule ^(myProject/([^/]+/)*([^/.]+))/$ http://localhost/$1 [R=301,L]
RewriteRule ^([^/.]+)$ index.php?cmd=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2&ajax=$3 [L,QSA]
RewriteEngine On
Options FollowSymLinks
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))/\ HTTP/
RewriteRule ^(applelearning/([^/]+/)*([^/.]+))/$ http://localhost/$1 [R=301,L]
RewriteRule ^([^/.]+)$ index.php?cmd=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2&ajax=$3 [L,QSA]
RewriteEngine On
Options FollowSymLinks
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))/\ HTTP/
RewriteRule ^(([^/]+/)*([^/.]+))/$ http://localhost/myProject/$1 [R=301,L]
RewriteRule ^([^/.]+)$ index.php?cmd=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)$ index.php?cmd=$1&action=$2&ajax=$3 [L,QSA]