<p>There's nothing unique or special for doing this with Craft CMS - you should be able to use this method for just about any web app running in a LAMP stack. <a href="https://stackoverflow.com/questions/9608366/remove-index-php-from-url-with-htaccess">See this post on removing index.php from the URL with Apache/mod_rewrite/.htaccess</a>.</p>

<p>TLDR: add this bit to the end of your .htaccess file before the closing  tag.</p>

<p>If Craft's index.php is at the domain root, such as example.com/index.php, this should do it:</p>

<pre><code># Redirect to same url without index.php
RewriteCond %{THE_REQUEST} ^GET./index\.php(/.*)?$ [NC]
RewriteCond %{REQUEST_URI} !^/index\.php/admin\b [NC]
RewriteRule ^index\.php(/(.*))?$ /$2 [R=302,NE,L]
</code></pre>

<p>If it lives in a subfolder, do this instead:</p>

<pre><code># Redirect to same url without index.php
RewriteCond %{THE_REQUEST} ^GET./subfolder/index\.php(/.*)?$ [NC]
RewriteCond %{REQUEST_URI} !^/subfolder/index\.php/admin\b [NC]
RewriteRule ^subfolder/index\.php(/(.*))?$ /$2 [R=302,NE,L]
</code></pre>

<p>(In both examples, replace <code>admin</code> on the 2nd line with whatever your site’s <a href="http://buildwithcraft.com/docs/config-settings#cpTrigger" rel="nofollow noreferrer">CP trigger</a> is set to, if you’ve changed it.)</p>

CC BY-SA 3.0
2015-09-03T18:46:13.170Z
Hm, I just tried this, however when testing locally, it appended the full path to my site to the URL:

http://domain.com/Users/username/Sites/client_site/site/app/
dauble
CC BY-SA 3.0
2015-09-03T19:01:24.103Z
Updated my answer; give it another whirl, maybe?
Nick Benson
CC BY-SA 3.0
2015-09-03T17:39:36.523Z
2015-09-03T20:21:38.467Z
2017-05-23T12:38:53.957Z
Nick Benson
<p>After playing around, I found a solution. I hope this helps anyone in the future:</p>

<pre><code># ------------------------------------------------------------
# Remove index.php
# ------------------------------------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

# ----------------------------------------------------------------------
# Send would-be 404 requests to Craft
# ----------------------------------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) /index.php?p=$1 [QSA,L]
</code></pre>

<p>Thanks, Nick for taking the time to help! It got me going in the right direction.</p>

CC BY-SA 3.0
2015-09-04T12:42:04.517Z
2015-09-04T12:42:04.517Z
dauble
<p>I am a little afraid to post this, but I'm running into an issue and haven't found a solution yet. I've been able to successfully remove the "index.php" from all my URLs, however I'm still finding that if I manually add "index.php" to any URL, I can still view the page and am not redirected to a URL without "index.php". For example:</p>

<pre><code>http://domain.com/events/
</code></pre>

<p>Works just fine, but if I visit <code>http://domain.com/index.php/events/</code> I can still view the page. Any idea on how to force it to redirect me to just <code>http://domain.com/events/</code>?</p>

<p>Here's my .htaccess file for reference:</p>

<pre><code># ----------------------------------------------------------------------
# Remove index.php from URLs
# ----------------------------------------------------------------------
&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On

  # Force trailing slash
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

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

  # Send would-be 404 requests to Craft
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
  RewriteRule (.+) index.php?p=$1 [QSA,L]
&lt;/IfModule&gt;
</code></pre>

<p>Is this even possible with Craft? Thanks in advance!</p>

<htaccess>
Removing index.php from URL even after .htaccess updates?
# Removing index.php from URL even after .htaccess updates?

(Asked by: username_0 on 2015-09-03)

I am a little afraid to post this, but I'm running into an issue and haven't found a solution yet. I've been able to successfully remove the "index.php" from all my URLs, however I'm still finding that if I manually add "index.php" to any URL, I can still view the page and am not redirected to a URL without "index.php". For example:
http://domain.com/events/

Works just fine, but if I visit http://domain.com/index.php/events/ I can still view the page. Any idea on how to force it to redirect me to just http://domain.com/events/?
Here's my .htaccess file for reference:
# ----------------------------------------------------------------------
# Remove index.php from URLs
# ----------------------------------------------------------------------

  RewriteEngine On

  # Force trailing slash
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

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

  # Send would-be 404 requests to Craft
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
  RewriteRule (.+) index.php?p=$1 [QSA,L]


Is this even possible with Craft? Thanks in advance!

**Tags:** htaccess


---

## 2 answers

### Answer by username_1 on 2015-09-03. Score: 2 | Accepted answer

There's nothing unique or special for doing this with Craft CMS - you should be able to use this method for just about any web app running in a LAMP stack. See this post on removing index.php from the URL with Apache/mod_rewrite/.htaccess.
TLDR: add this bit to the end of your .htaccess file before the closing  tag.
If Craft's index.php is at the domain root, such as example.com/index.php, this should do it:
# Redirect to same url without index.php
RewriteCond %{THE_REQUEST} ^GET./index\.php(/.*)?$ [NC]
RewriteCond %{REQUEST_URI} !^/index\.php/admin\b [NC]
RewriteRule ^index\.php(/(.*))?$ /$2 [R=302,NE,L]

If it lives in a subfolder, do this instead:
# Redirect to same url without index.php
RewriteCond %{THE_REQUEST} ^GET./subfolder/index\.php(/.*)?$ [NC]
RewriteCond %{REQUEST_URI} !^/subfolder/index\.php/admin\b [NC]
RewriteRule ^subfolder/index\.php(/(.*))?$ /$2 [R=302,NE,L]

(In both examples, replace admin on the 2nd line with whatever your site’s CP trigger is set to, if you’ve changed it.)

> **Comments:**
> **username_0**: Hm, I just tried this, however when testing locally, it appended the full path to my site to the URL:  http://domain.com/Users/username/Sites/client_site/site/app/  
> **username_1**: Updated my answer; give it another whirl, maybe?  

---

### Answer by username_0 on 2015-09-04. Score: 2

After playing around, I found a solution. I hope this helps anyone in the future:
# ------------------------------------------------------------
# Remove index.php
# ------------------------------------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

# ----------------------------------------------------------------------
# Send would-be 404 requests to Craft
# ----------------------------------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) /index.php?p=$1 [QSA,L]

Thanks, Nick for taking the time to help! It got me going in the right direction.


---

