URL rewrite not working

Problems with the Windows version of XAMPP, questions, comments, and anything related.

URL rewrite not working

Postby vdecree » 26. January 2015 21:39

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>
vdecree
 
Posts: 1
Joined: 26. January 2015 21:35
Operating System: Windows 7

Re: URL rewrite not working

Postby Nobbie » 27. January 2015 14:20

Any hints in the error log?

Probably a missing or insufficient "AllowOverride" Clause for myproject.local?
Nobbie
 
Posts: 8761
Joined: 09. March 2008 13:04

Re: URL rewrite not working

Postby gsmith » 27. January 2015 23:06

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>

gsmith
 
Posts: 194
Joined: 29. November 2013 18:04
Location: San Diego
XAMPP version: 0.0.0
Operating System: Win XP to 2012R2/VS 6,9,11,14


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 66 guests