1 Replies - 2866 Views - Last Post: 03 September 2013 - 06:10 PM

#1 Ntwiles   User is offline

  • D.I.C Addict

Reputation: 148
  • View blog
  • Posts: 831
  • Joined: 26-May 10

Rewriting urls

Posted 03 September 2013 - 03:29 PM

I'm trying to use mod_rewrite to do a number of things:

1. Redirect www to non-www.
2. Remove /index.php from displaying on my index page.
3. Remove *.php extension from all other page urls.

Here is my .htacces file:

ErrorDocument 404 /error404.php

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^www.designmygame.com [nocase]
RewriteRule ^(.*)         http://designmygame.com/$1 [last,redirect=301]

#Remove .php
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

The www to non-www rewrite works perfectly, and I CAN access a php file by typing in just the filename without the extension, but the url in the address bar doesn't rewrite to remove the .php extension like I would like it to. The last script to remove index.php doesn't function at all.

So my question is, is there a way to get this to work as desired using only .htaccess, or do I need to use something like HTML5's history.pushstate in addition to achieve desired results?

Is This A Good Question/Topic? 0
  • +

Replies To: Rewriting urls

#2 snoj   User is offline

  • Married Life
  • member icon

Reputation: 93
  • View blog
  • Posts: 3,583
  • Joined: 31-March 03

Re: Rewriting urls

Posted 03 September 2013 - 06:10 PM

I think you're looking for RedirectMatch directive.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1