Q2: Why doesn't this config code work in .htaccess?
What will I use instead of Document_Root in .htaccess ??
Below is my htttp.conf of my Linux server.
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.php -f
RewriteRule ^/(.*)(/?)$ /$1.php [L]
RewriteRule ^/([a-zA-Z]+)([a-zA-Z0-9_]{3,15})(/?)$ /profile.php?fairid=$1$2 [L]
RewriteRule ^/([a-zA-Z]+)([a-zA-Z0-9_]{3,15})/([a-z]*)(/?)$ /$3.php?fairid=$1$2 [L]
But now I have moved my domain to a shared server. So, for my site to work properly, what changes would be required to .htaccess in the rewrite rules?
My .htaccess looks like this:
RewriteEngine On
RewriteBase /~laborfa2
RewriteCond %/~laborfa2/lf/main/com/%{REQUEST_FILENAME}.php -f
RewriteRule /(.*)(/?)$ /~laborfa2/lf/main/com/$1.php [L]
RewriteRule ^/([a-zA-Z]+)([a-zA-Z0-9_]{3,15})(/?)$ /~laborfa2/lf/main/com/profile.php?fairid=$1$2 [L]
But it doesn't work. Please imagine that changes will be needed in .htaccess.
REQUEST_FILENAME
is already an absolute file system path and the prefix is DOCUMENT_ROOT
invalid.
Also, when using mod_rewrite in the .htaccess file, Apache removes the path prefix for each directory from the requested URI path before testing the rules. And in the case of the .htaccess file in the document root of the webserver, it takes the lead /
. This way, your template should not start with a leading slash, for example, in a server or virtual host configuration.
So try this:
RewriteBase /~laborfa2/
RewriteCond %{DOCUMENT_ROOT}~laborfa2/lf/main/com/$1.php -f
RewriteRule (.*)(/?)$ /lf/main/com/$1.php [L]
RewriteRule ^([a-zA-Z]+[a-zA-Z0-9_]{3,15})(/?)$ /lf/main/com/profile.php?fairid=$1 [L]
a source to share