Page 1 of 1

URL rewrite not working

PostPosted: 26. January 2015 21:39
by vdecree
Hi there,

I'm currently running a project outside of the normal htdocs folder. I have a host file setup so that I can run things from a dev folder. So I can visit a URL such as:
Code: Select all
myproject.local
- which works fine. The problem I encounter is when I try usea .htaccess file to remove the .php file endings.. nothing works. The URL rewrite just doesn't seem to take effect. I'm wondering if it's due to being outside of the htdocs folder?

My .htaccess:
Code: Select all
<IfModule mod_rewrite.c> 
   RewriteEngine on
   RewriteRule ^blog/([a-zA-Z0-9-/]+)/preview$ /blog/post.php?s=$1&preview=all [L]
   RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]
   RewriteRule ^category/([a-zA-Z0-9-/]+)$ /blog/archive.php?cat=$1 [L]
   RewriteRule ^tag/([a-zA-Z0-9-/]+)$ /blog/archive.php?tag=$1 [L]

   # Redirect to PHP if it exists.
   # e.g. example.com/foo will display the contents of example.com/foo.php

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME}.php -f
   RewriteRule ^(.+)$ $1.php [L,QSA]
</IfModule>

Re: URL rewrite not working

PostPosted: 27. January 2015 14:20
by Nobbie
Any hints in the error log?

Probably a missing or insufficient "AllowOverride" Clause for myproject.local?

Re: URL rewrite not working

PostPosted: 27. January 2015 23:06
by gsmith
URL rewriting is an art form in and of itself that I am not versed well enough in (and I really should be). One thing that does strike me in your example is the use of the ^ anchor. "blog" etc may not actually be the beginning of the string it sees (as I believe it sees "/" as the first character) thereby never matching. Again, I am not well versed in this art form but you may also need

RewriteBase /

Here's an example from a CMS I use
Code: Select all
# handle rewrites for fancy urls
<IfModule mod_rewrite.c>
   RewriteEngine on

   # Usually RewriteBase is just '/', but
   # replace it with your subdirectory path
   RewriteBase /

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule /?([A-Za-z0-9_-]+)/?$ index.phtml?id=$1 [QSA,L]
</IfModule>