views:

35

answers:

2

I am using Apache 2.2 and mod_rewrite. I would like to take the following urls and map them to another url. The pattern is simple and like this:

http://domain/test/ex1.html -> http://domain/app/index.php/content/?name=ex1

I tried the following in an .htaccess file (place in /test/ directory in docroot):

RewriteEngine On
RewriteBase /app/
RewriteRule (.*)\.html index.php/content/?name=$1

and

RewriteEngine On
RewriteRule (.*)\.html /app/index.php/content/?name=$1

I wasn't sure if the backreference was correct so set to $0 and $2 but never seemed to help.

I also tried setting the RewriteLogLevel to 9.

There is a step where it is almost there: rewrite 'ex1.html' -> 'index.php/content/?name=ex1'

The last line of the rewrite log is as follows: [perdir /var/www/domain/htdocs/test/] internal redirect with /app/index.php/content/ [INTERNAL REDIRECT]

How can I get this to rewrite to /app/index.php/content/?name=ex1 ?

EDIT so using this as an .htacces in the docroot file works for the RedirectMatch:

RewriteEngine On 
RewriteBase /
RedirectMatch ^(.*)/(.*)\.html$ http://domain/app/index.php/content/?name=$2
 #this doesnt work - adding to docroot allows for it to pick up but still using test/ex1 rather than just ex1
#RewriteRule ^(.*)\.html$ /app/index.php/content/?name=$1

Any help getting the bottom RewriteRule (that is currently commented out) to work would be appreciated.

thanks

A: 

Uhm, off the top of my head:

RewriteCond %{REQUEST_URI} ^/app/(.*)\.html$
RewriteRule ^/app/(.*)\.html$ /app/index.php/content/?name=$1

This assumes that the rewrite base is /

ivans
looks like app -> test based upon dir structure above?
timpone
I'm not sure I understand your comment. If the original URI is /test/foo.html, and the destination is /app/index.php/content/?name=foo, then check out my edited answer...
ivans
I'm pretty sure that the /content/ in the rewrite is causing mod_rewrite to have problems as it's taking into account the path (test) in this case
timpone
i'm assuming this won't work in .htaccess file. need a way to strip out leading dir name test
timpone
+1  A: 

In your example you mentioned domain/test/ so I'm going based of rewriting from /test/*.html to /app/index.php/content/?name=

RewriteEngine On
RewriteBase /
RewriteRule ^test/(.*)\.html$ /app/index.php/content/?name=$1

That should work.

Marco Ceppi
hmmm.... rereading my original post as this doesn't seem to be working. I'm assuming this would be an .htaccess file located in the docroot? For some reason, it is still not working. ugh..
timpone
for the backreference it's passing the test of the directory so test/ex1 rather than just ex1 is being inserted at $1. thx for any help
timpone