Thread Rating:
  • 4 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove index.php from URL
#1
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!
Reply
#2
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.
Reply
#3
Was always wondering how to do this, thanks!
Reply
#4
What is the point of this?
Reply
#5
Turn http://example.org/index.php into http://example.org basically.
Reply
#6
Nice idea thank you. Smile
Reply
#7
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.
Reply
#8
This user has been denied support. This user has been denied support.
Try adding QSA

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

That should keep the ?action=quicktheme intact.
Reply
#9
(01-07-2011, 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]
Reply
#10
This user has been denied support. This user has been denied support.
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]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)