Forum Moderators: phranque
RewriteEngine On
#RewriteBase /news
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?category=$1 [L]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Basically this says if a file exsits then go to it else direct it to index.php.
I am losing my non-www to www functionality given in my main sites htaccess which is
I have doubts about this, and the more I think about the code I think it is in the actual script rather than this htaccess, but is there any way possible to have actual articles as name.php? In the example above all categories and actual articles are shown as folders for the url. So something like www.example.com/category/article1.php instead of www.example.com/category/article1/
Redirects work on URL requests coming from outside, not on files inside the server.
htaccess cannot and does not "make" URLs.
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?category=$1 [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
<IfModule mod_php4.c>
php_value session.use_trans_sid 0
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?category=$1 [L]
function site() {
$host = 'http://'.$_SERVER['HTTP_HOST'];
$directory = dirname($_SERVER['SCRIPT_NAME']);
$website = $directory == '/' ? $host.'/' : $host.$directory.'/';
return $website;
}
root htaccess: RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news/([^/.]+)$ /news/index.php?category=$1 [L] ^news/([^/.]+)$ could be ^news/(([^/]+/)*[^/.]+)$ for multiple folder levels. /news/ htaccess: php_value session.use_trans_sid 0
SecFilterEngine Off
SecFilterScanPOST Off
http://www.example.com/news/index.php?category=cat-example/subcat-example/ http://www.example.com/news/cat-example/subcat-example/
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?category=$1 [L]
In its current state... if I were to go to example.com/news/ it would redirect to www.example.com/news/ (because of my sites root htaccess which does this and I'm assuming because there is a physical index.php file in this location.
Now, if I type example.com/news/category1/etc./ it does not redirect and just shows without the www.