MyBB Community Forums

Full Version: Remove index.php from URL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hi,

this is a very simple way to remove the index.php from your URL. Please note that this only works if you are running an Apache web server and mod_rewrite is enabled!

Just add the following lines to your root .htaccess file (directly after RewriteEngine On):

RewriteCond %{IS_SUBREQ} false
RewriteRule ^index.php$ http://www.example.org [R=301,L]

Of course you have to replace www.example.org wit your own MyBB installation. For example:

RewriteRule ^index.php$ http://community.mybb.com [R=301,L]
(this will work on this domain)

RewriteRule ^index.php$ http://www.example.org/board/ [R=301,L]
(if you installed MyBB in a sub folder)

The trick is the IS_SUBREQ: So the redirect will not work in sub directories like /admin or /archive (the index.php have to stay there) and it will no affect POST or GET requests!
What a real lifesaver! I can't tell you how immensely beneficial this trick has been for me...and is going to be for everyone else looking to remove index.php from Mybb. I did that standard .htaccess 301 redirect and my forum admin section stopped working...this tricks has brought it back.

Now, the next step is to remove the references of index.php in Global template and other places.

Thank you.
Was always wondering how to do this, thanks!
What is the point of this?
Nice idea thank you. Smile
querschlaeger,

this works good, but it conflicts with the quick theme plugin.

when users go to switch themes using the plugin, with your modifications, it adds this to the end of the url:
?action=quicktheme

but doesn't do anything. once I removed your modification from the .htaccess, the quick theme worked as normal.
Try adding QSA

[R=301,L,QSA]
instead of
[R=301,L]

That should keep the ?action=quicktheme intact.
(2011-01-07, 10:31 PM)frostschutz Wrote: [ -> ]Try adding QSA

[R=301,L,QSA]
instead of
[R=301,L]

That should keep the ?action=quicktheme intact.

doing the same as before:
http://www.paforliberty.com/forum/?action=quicktheme

after modifying the .htaccess as you suggested:
RewriteEngine on

# Google SEO workaround for search.php highlights:
# Make this rule the first rewrite rule in your .htaccess!
RewriteRule ^([^&]*)&(.*)$ http://paforliberty.com/forum/$1?$2 [L,QSA,R=301]

# Google SEO Sitemap:
RewriteRule ^sitemap\-([^./]+)\.xml$ misc.php?google_seo_sitemap=$1 [L,QSA,NC]

# Google SEO URL Forums:
RewriteRule ^Forum-([^./]+)$ forumdisplay.php?google_seo_forum=$1 [L,QSA,NC]

# Google SEO URL Threads:
RewriteRule ^Thread-([^./]+)$ showthread.php?google_seo_thread=$1 [L,QSA,NC]

# Google SEO URL Announcements:
RewriteRule ^Announcement-([^./]+)$ announcements.php?google_seo_announcement=$1 [L,QSA,NC]

# Google SEO URL Users:
RewriteRule ^User-([^./]+)$ member.php?action=profile&google_seo_user=$1 [L,QSA,NC]

# Google SEO URL Calendars:
RewriteRule ^Calendar-([^./]+)$ calendar.php?google_seo_calendar=$1 [L,QSA,NC]

# Google SEO URL Events:
RewriteRule ^Event-([^./]+)$ calendar.php?action=event&google_seo_event=$1 [L,QSA,NC]

# Google SEO 404:
ErrorDocument 404 /forum/misc.php?google_seo_error=404

# Google SEO URL Forums:
RewriteRule ^forum\-([^./]+)$ forumdisplay.php?google_seo_forum=$1 [L,QSA,NC]

# Google SEO URL Threads:
RewriteRule ^thread\-([^./]+)$ showthread.php?google_seo_thread=$1 [L,QSA,NC]

# Google SEO URL Announcements:
RewriteRule ^announcement\-([^./]+)$ announcements.php?google_seo_announcement=$1 [L,QSA,NC]

# Google SEO URL Users:
RewriteRule ^user\-([^./]+)$ member.php?action=profile&google_seo_user=$1 [L,QSA,NC]

# Google SEO URL Calendars:
RewriteRule ^calendar\-([^./]+)$ calendar.php?google_seo_calendar=$1 [L,QSA,NC]

# Google SEO URL Events:
RewriteRule ^event\-([^./]+)$ calendar.php?action=event&google_seo_event=$1 [L,QSA,NC]

RewriteCond %{IS_SUBREQ} false
RewriteRule ^index.php$ http://www.paforliberty.com/forum [R=301,L,QSA]
Sorry, my bad. QSA is for rewrites, not redirects... Blush

Maybe like this:

RewriteCond %{QUERY_STRING} ^(..*)$
RewriteRule ^index\.php$ http://yoursite/mybb/?%1 [L,NS,R=301]
RewriteRule ^index\.php$ http://yoursite/mybb/ [L,NS,R=301]

Or if Apache is smart even just

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^index\.php$ http://yoursite/mybb/?%1 [L,NS,R=301]
Pages: 1 2 3