Forum Moderators: phranque

Message Too Old, No Replies

.htaccess question

URL modification

         

alias

1:35 pm on Jun 12, 2004 (gmt 0)

10+ Year Member



Hi all,

I know there is a way to make it, but I do not really know, how.
Here's what I want:
When I enter the URL e.g. domain.ext/variable/value, the Apache should modify it to domain.ext/index.php/variable/value
How should the .htaccess file look like in this case?

Thank You all very much,
alias

leadegroot

2:27 pm on Jun 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The content should simply be:


Options +FollowSymLinks
RewriteEngine on

RewriteRule ^variable/value/$ /index.php/variable/value/ [L]

ie. the page you are looking for goes between the ^ and the $
and the page you wish to go to appears from the web root
I assumed you dont want the url displayed to change - if you do, then change [L] to [R=301,L]

You can learn more at
[webmasterworld.com ]
and more advanced stuff at:
[httpd.apache.org ]
and
[engelschall.com ]

HIH

alias

3:13 pm on Jun 12, 2004 (gmt 0)

10+ Year Member



Thanks, that is almost everything what I need. But as far as I understand - it will only modify the /variable/value URL's. What about /something/something2? It should also be rewrited to /index.php/something/something2. How should the rule look in this case?

Thanks again,
alias

jdMorgan

3:52 pm on Jun 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alias,

Please see our charter [webmasterworld.com]. We will be happy to answer specific questions about your code, and to help you learn to write good code, but we are not a free code-writing service. There are hundreds of threads [google.com] here dealing with rewrites, and the documentation from Apache is worth a read. With respect, bad mod_rewrite code can seriously mess up your site, so you must be an informed user to avoid disaster.

The technique you are looking for is called a "back-reference" and is discussed in the mod_rewrite documentation of the RewriteRule and RewriteCond directives.

Refs:
Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular Expressions Tutorial [etext.lib.virginia.edu]

Jim

alias

4:07 pm on Jun 12, 2004 (gmt 0)

10+ Year Member



Thanks for everything, I'm a fast-learner but it is sometimes kind of hard to find what you need if you know what I mean.

Respect,
alias