yuvilio
yuvilio

Reputation: 4185

Removing index.php from some ExpressionEngine 2 paths

I set up ExpressionEngine 2.4 with clean urls per the User Guide instructions. They work great. But when I use path single variables from, say the channel entries tag, I still get "index.php" in the path. For example:

{exp:channel:entries channel="news"}
  ..
  <a href="{comment_url_title_auto_path}">Test</a>
{/exp:channel:entries}

Renders to:

<a href="http://eetest/index.php/mothra-is-attacking">Test</a>

I currently have a workaround consisting of two parts:

First, I scrub the "index.php" from the url using the Find and Replace Plus plugin:

{exp:channel:entries channel="news" limit="1"} 
    <a href="{exp:replace_plus find="index.php/"}
             {comment_url_title_auto_path}
           {/exp:replace_plus}">Test</a>
{/exp:channel:entries}

Which gives me the working clean url:

<a href="http://eetest/mothra-is-attacking">Test</a>

Second, in case I ever miss a url in the templates, I make sure that any url that has "index.php" in it is redirected to ones that don't have one. In my .htaccess I use this clause:

# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteCond %{THE_REQUEST} ^GET
RewriteRule ^index\.php(.+) $1 [R=301,L] 

So while this setup works it's cluttered (makes me sprinkle find/replace on my links in my templates) and a bit inefficient (forces redirects in some cases), and it's not completely SEO friendly (for those urls that render with index.php).

My question is, is there some setting I'm missing to prevent index.php from showing up in some of these paths in the first place?

Here are some relevant settings in my config.php:

$config['index_page'] = ''; //per the user docs on removing index.php
$config['uri_protocol'] = 'AUTO'; //didn't have luck with the other values
$config['base_url'] = '';
$config['url_suffix'] = '';

Upvotes: 1

Views: 531

Answers (2)

Jean St-Amand
Jean St-Amand

Reputation: 793

Another way to handle this is with Deploy Helper or Reelocate - two excellent add-ons that pull all of the path vars that are ordinarily spread out throughout the control panel into one spot so you can quickly and easily find and replace them with a single button click. That way any stray index.php references that would affect your auto paths will be found and updated in one shot. Both great tools.

Upvotes: 1

yuvilio
yuvilio

Reputation: 4185

Found it.

I had to go to Admin->Channel Administration->Channels and click on "Edit Preferences" for each of my channels.

There, I removed the "index.php" from the "Channel URL" field in the "Path Settings" section.

After hitting update and refreshing my front end page. All the index.php in the paths shown above were gone. Workarounds no longer needed!

Upvotes: 1

Related Questions