converting dynamic urls to static using mod_rewrite

They have: 5,633 posts

Joined: Jan 1970

I'm a non-programmer trying to figure out how mod_rewrite works. Set up the following as a test:
mydomain.com/rewrite_test/index.php

This page has a link on it that goes to

mydomain.com/rewrite_test/details/index.php?SEL=test1

Where SEL is an include file that is loaded out of

mydomain.com/rewrite_test/includes

I placed the .htaccess file in the /rewrite_test/ directory.

this file currently reads:
RewriteEngine on
RewriteBase /rewrite_test/
RewriteRule ^details/(.*)/(.*)/$ /index.php?$1=$2 [T=application/x-httpd-php,L]

This is like the tenth time I've rewritten the .htaccess file and nothing seems to be happening. I have server access and the module is properly loaded. (In my earliest attempts I did manage to get an internal server error message, so I know it works when I've got my syntax all screwed up)Smiling

I want to make the url look like

mydomain.com/rewrite_test/details/test1.php

How do I make this happen?

They have: 601 posts

Joined: Nov 2001

Hi

Sorry, I don't quite grasp your message. You have the following URL:

mydomain.com/rewrite_test/details/index.php?SEL=test1

And you want the URL in the browser window to show:

mydomain.com/rewrite_test/details/test1.php

A very simple way to achieve this would be to use one frame at the second URL and load the content of the first URL into it, thus keeping the browser window location to the second (more frindly URL).

If I have misunderstood your question and that you are trying to take advanatge of the mod_rewrite module, then maybe the following guide will help you. I doubt that you need such a complex regex.

http://www.engelschall.com/pw/apache/rewriteguide/

- wil

They have: 5,633 posts

Joined: Jan 1970

You're over complicating things here. To achieve what you want, all you need is the following:

RewriteEngine on
RewriteRule ^/rewrite_test/details/(.*)\.php$ /index.php?SEL=$1 [L]
'Now when you type in mydomain.com/rewrite_test/details/test1.php, Apache will display mydomain.com/rewrite_test/details/index.php?SEL=test1

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Welcome to TWF, paulj.

Thanks for the info!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.