Masking Subdirectories

Discuss practical ways rearrange URLs using mod_rewrite.

Masking Subdirectories

Postby Gregh » Tue Nov 04, 2008 7:06 am

Greetings....

I've been having some issues getting my .htaccess file to rewrite my urls. I am using Joomla. To get to my first content page, one has to type

www.mydomain.ca/joomla

then, from that point, links to menu items are:

www.mydomain.ca/joomla/about
www.mydomain.ca/joomla/faq
www.mydomain.ca/joomla/contact

I would like to get rid of the /joomla/, so that the navigation bar will show

www.mydomain.ca/about
www.mydomain.ca/faq
etc...

I'm sorry to ask what is likely such an incredibly simple question, but I've been searching around, trying various things, and have not had any luck.

Edited - 11/03 to change subject from 'Masking Subdomains' to 'Masking subdirectories'.
Gregh
 
Posts: 2
Joined: Tue Nov 04, 2008 7:02 am

Postby richardk » Tue Nov 04, 2008 10:39 am

Do you have a .htaccess file with mod_rewrite already? If you do, post it and say where it is.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Gregh » Tue Nov 04, 2008 11:12 am

richardk wrote:Do you have a .htaccess file with mod_rewrite already? If you do, post it and say where it is.


First off, thank you for the reply.

Mod_Rewrite is enabled through Apache's httpd.conf file and it functions properly. The base install uses the following URL structure...

www.mydomain.ca/joomla/index.php/about

whereas my URLs are now structured...

www.mydomain.ca/joomla/about

.htaccess is located in the htdocs folder within the Joomla directory - (apps\joomla\htdocs\.htaccess). Saving the file here let me get rid of the 'index.php', which was included within the URLs. However, it is interesting that you brought the placement up, as I've been tempted to save a copy of that file up one level - at apps\joomla\.htaccess

Attached you will find my (almost) complete .htaccess file. I removed the header data as I don't imagine you are much interested in Joomla's copyright info, or in the 'use a # to ignore a line' info. Let me know if you would like that header - it is some exciting reading...=)

The one argument I'm especially curious about is 'Rewrite base /joomla' When I remove it, I get 'page not found' errors, but I can't logically understand why I'm adding in the /joomla when I want to remove the /joomla from the visible URLs....

-----------------------------------------

## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks

#
# mod_rewrite in use

RewriteEngine On

########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits

# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root)


RewriteBase /joomla

########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section
Gregh
 
Posts: 2
Joined: Tue Nov 04, 2008 7:02 am

Postby richardk » Wed Nov 05, 2008 1:29 pm

.htaccess is located in the htdocs folder within the Joomla directory - (apps\joomla\htdocs\.htaccess). Saving the file here let me get rid of the 'index.php', which was included within the URLs. However, it is interesting that you brought the placement up, as I've been tempted to save a copy of that file up one level - at apps\joomla\.htaccess

The .htaccess file needs to be at example.com/.htaccess. If it is in a sub directory the sub directory must appear in the URL.

The one argument I'm especially curious about is 'Rewrite base /joomla' When I remove it, I get 'page not found' errors, but I can't logically understand why I'm adding in the /joomla when I want to remove the /joomla from the visible URLs....

It's adding /joomla to the index.php path to make /joomla/index.php.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [NC,OR]
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [NC,OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [NC,OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) [NC]
RewriteRule .* - [F,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (/|\.php|\.html?|\.feed|\.pdf|\.raw|/[^.]*)$ /joomla/index.php [NC,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 6 guests

cron