Forum Moderators: phranque

Message Too Old, No Replies

.htaccess issue - redirecting to homepage

         

jshpik1

11:06 am on Feb 3, 2008 (gmt 0)

10+ Year Member



Hello,

I'm installing Media Wiki in a sub directory on my site, in the root directory I'm using phpbb2 with some URL rewrites. From a Media Wiki article, users have put that there's a few lines you need to add to htaccess file in order to do the URL rewrites. However, it's redirecting to the homepage of my website with no CSS file. Here's the htaccess file:

# Media Wiki
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^(.+) /heavy-metal-wiki/$1 [L]

# redirect to main page
RewriteRule ^/*$ /index.php?title=Main_Page [L,QSA]

# anything else is to be treated as a title
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^(.+)$ /index.php?title=$1 [L,QSA]

# Redirect from example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

# FORUM INDEX (un-comment if used) FOR PHPBB2
# RewriteRule ^index\.html$ /index.php [QSA,L,NC]
# FORUM PROTECTION RULE
# RewriteRule ^[a-z0-9_-]+/([^/]+\.html)$ /index.php [R=301,L,NC]
# CATEGORIES
RewriteRule ^[a-z0-9_-]*-c([0-9]+)\.html$ /index.php?c=$1 [QSA,L,NC]
# PAGINATED FORUM
RewriteRule ^[a-z0-9_-]*-f([0-9]+)-([0-9]+)\.html$ /viewforum.php?f=$1&start=$2 [QSA,L,NC]
# FORUM
RewriteRule ^[a-z0-9_-]*-f([0-9]+)\.html$ /viewforum.php?f=$1 [QSA,L,NC]
# PAGINATED TOPIC
RewriteRule ^[a-z0-9_-]*-t([0-9]+)-([0-9]+)\.html$ /viewtopic.php?t=$1&start=$2 [QSA,L,NC]
# TOPIC
RewriteRule ^[a-z0-9_-]*-t([0-9]+)\.html$ /viewtopic.php?t=$1 [QSA,L,NC]
# POST
RewriteRule ^post([0-9]+)\.html$ /viewtopic.php?p=$1 [QSA,L,NC]
#PROFILES
RewriteRule ^member([0-9]+)\.html$ /profile.php?mode=viewprofile&u=$1 [QSA,L,NC]
# RSS main
RewriteRule ^rss-?(l¦s)?-?(m)?\.(xml(\.gz)?)$ /rss.php?$1&$2 [L]
# RSS forums
RewriteRule ^forums-rss-?(l¦s)?-?(m)?\.(xml(\.gz)?)$ /rss.php?forum&c&$1&$2 [L]
# RSS all
RewriteRule ^([a-zA-Z0-9_-]+)-rss([0-9]*)-?(l¦s)?-?(m)?\.(xml(\.gz)?)$ /rss.php?$1=$2&$3&$4 [L]
# RSS forum topics
RewriteRule ^.+-rf([0-9]+)-?(l¦s)?-?(m)?\.(xml(\.gz)?)$ /rss.php?forum=$1&$2&$3 [L]
# SitemapIndex
RewriteRule ^sitemaps\.(xml(\.gz)?)$ /sitemap.php [L]
# Sitemap modules
RewriteRule ^([a-zA-Z0-9_-]+)-sitemap\.(xml(\.gz)?)$ /sitemap.php?$1 [L]
# Forum Sitemaps
RewriteRule ^.+-gf([0-9]+)\.(xml(\.gz)?)$ /sitemap.php?forum=$1 [L]
# Yahoo! urllist.txt
RewriteRule ^urllist\.(txt(\.gz)?)$ /urllist.php [L]

Thanks for the assistance.

[edited by: jdMorgan at 9:28 pm (utc) on Feb. 3, 2008]
[edit reason] example.com [/edit]

jshpik1

9:48 am on Feb 4, 2008 (gmt 0)

10+ Year Member



Basically it's displaying the main page of the wiki as http://www.example.com/heavy-metal-wiki/Main_Page, only it's showing my homepage at http://www.example.com.

jdMorgan

8:09 pm on Feb 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's a bit too much code for most folks here to digest, since we're not familiar with your site.

However, one thing that may help is to put your rules in the proper order:

Put all external redirect ([R=30x]) rules first, in order from most-specific pattern to least-specific pattern. Follow those with your internal rewrites, again in order from most-specific pattern to least-specific pattern.

The rule using a ".+" pattern and file/dir-exists checks should be one of the last internal rewrites, and your domain canonicalization rule should be the last external redirect.

It's critical to do all the redirects first, otherwise, you can 'expose' your internal filepaths to visitors and search engines.

Be careful, you've mis-labeled at least one internal rewrite as a redirect in the comments.

Jim