I want to do a cloaked htaccess redirect from my root to the sub so therefore I have just installed a moodle in a subdirectory. I dont know how to use htaccess file so please help me with it.
Printable View
I want to do a cloaked htaccess redirect from my root to the sub so therefore I have just installed a moodle in a subdirectory. I dont know how to use htaccess file so please help me with it.
Try this code:
Also see the RewriteBase directive for your sub-directory's .htaccess file:Code:/.htaccess (htdocs root)
#other rules from above here
RewriteRule ^friendster/([0-9]+)/([^/]+)\.html$ /friendster/search.php?query=$2&search=1&start=$1&a=1 [L]
RewriteRule ^friendster/(.*)\.html$ /friendster/search.php?query=$1&search=1&a=1 [L]
RewriteRule ^friendster/(.*)-(.*).html?$ /friendster/details.php?id=$1&titlecode=$titlecode3=$2 [L]
RewriteRule ^friendster/preview/(.*)-(.*).html?$ /friendster/preview.php?id=$1&titlecode=$titlecode3=$2 [L]
http://httpd.apache.org/docs/2.2/mod...ml#rewritebase
The best way to manage the change of site’s URL due to movement of directory location is by using redirection feature provided by mod_rewrite module in Apache HTTPD web server. Most web hosts using Apache web server supports mod_rewrite redirect by default, and can implement this trick with ease. Else you will need to enable and turn on mod_rewrite module.
To redirect from a subdirectory or sub-folder to root directory, add the following line of text towards the top of .htaccess file located in the sub-directory to redirect all requests into that folder will be redirected to new location (i.e. root) properly. If the .htaccess file does not exist, create one.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^mylovelysite/(.*)$ /$1 [R=301,NC,L]
</IfModule>
Replace mylovelysite in the forth line above with the directory name on your website’s URL. These line in .htaccess will redirect requests for the /mylovelysite sub-directory to the root directory by stripping “mylovelysite/” out of the URL. For example, a visit to http://www.domain.com/mylovelysite/index.html will get redirected to http://www.domain.com/index.html, instead of returning an 404 error. This is useful for visitors who come to your site via bookmark or favorite, or those find your web pages via search engines that haven’t re-crawled, re-spidered and refreshed with the new URLs in their search indexes in the initial days after moving.
Source: mydigitallife.info
.htaccess uses apache rewrite.
I'm not sure if you're refering to using rewrite rules in httpd.conf or not, but using .htaccess, you have the same availability to the apache rewrite engine without having to restart apache (as long as mod_rewrite is already turned on).
other than that, it's really just a matter of preference, and the fact that a bad rewrite rule will result in a 500 error, it's nice to keep that 500 error localized.