2

I have a URL structure like this

http://domain.com/page/thing1
http://domain.com/page/thing2
http://domain.com/page/thing3

I want to:

  • remove /page/ from the URL
  • serve up content from /page/thing1

I am using ExpressionEngine, so here's what I do to remove index.php from the URL

<IfModule mod_rewrite.c>
        RewriteEngine On

        # Removes index.php
        RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
Dan
  • 3,264
  • 5
  • 33
  • 58
  • You don't necessarily have to do this via ModRewrite, depending on how you're accessing this data in EE. Are these URLs created via the Pages module? Or is `page` a template group and `thing1` a template? Or are `thing1`, `thing2` etc, all entry URL titles? – Derek Hogue Jan 16 '12 at 20:39
  • Here are two posts which may help http://stackoverflow.com/questions/2402140/use-a-subdirectory-as-root-with-htaccess-in-apache-1-3 and http://stackoverflow.com/questions/990392/htaccess-rewrite-to-redirect-root-url-to-subdirectory – Anagio Jan 16 '12 at 20:55
  • @DerekHogue right now I have it set up where page is a template group and thing1 and thing 2 are entries. – Dan Jan 16 '12 at 21:20
  • In that case, [see rjb's answer](http://stackoverflow.com/a/8890130/174299) - the Pages module is the way to go here. Accessing individual entries by their URL title via the first segment is not a good route to take. – Derek Hogue Jan 17 '12 at 15:09

3 Answers3

1

What are the gains to be had from these new URLs?

Simply removing the /page URL segment (i.e. template group) from your URIs creates a lot of additional overhead and complexity, as illustrated in the following ExpressionEngine URL Schematic:

ExpressionEngine URL Schematic

The native ExpressionEngine Pages Module or the third-party Structure Module is the simplest method and won't require adding any RewriteRules rules to your .htaccess file.

However, this will require you to create a page URL for each entry, which may be less than ideal.

rjb
  • 8,388
  • 2
  • 41
  • 46
0

If you change all your urls to be http://domain.com/thing1 and http://domain.com/thing2 etc, couldn't you just add the page/ back in when you rewrite to the index.php file?

RewriteRule ^(.*)$ /index.php/page/$1 [L]
Jon Lin
  • 135,941
  • 26
  • 200
  • 209
  • This would assume *all requests* would be routed thru the `/pages` template group, which would break many URIs — including many core ExpressionEngine URLs. At a minimum, you'd have to combine the `RewriteRule` with a `RewriteCond`. – rjb Jan 17 '12 at 05:17
0

Append these lines below your existing Rewrite rule in IfModule block:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!page/)(.*)$ /page/$1 [L,NC]
anubhava
  • 664,788
  • 59
  • 469
  • 547