Click to See Complete Forum and Search --> : Rewrite rule - complete noob - help please :)


Znupi
04-18-2007, 01:42 PM
Ok, so I never wrote a rewrite rule in my life. I know they use pattern matching but have no idea of their syntax. All I know (although I'm not so sure about it) is that you put rewrite rules in a file you call .htaccess and place that in the folder you want the rules to be applied in.

Right now I'm working on a site that uses this kind of links: http://example.com/index.php/subpage/another/lastone . The link parsing is done in PHP but I need a rewrite rule to remove 'index.php' from the address, so the links will become http://example.com/subpage/another/lastone . Anyone know how this could be achieved? Or, any good tutorials about it? I love tutorials :).

bokeh
04-18-2007, 03:00 PM
What's this got to do with PHP?

Znupi
04-18-2007, 03:30 PM
Didn't know where else to post.

Taschen
04-18-2007, 06:07 PM
This can be done fairly straight forwardly using htaccess. Try this search
http://www.google.co.uk/search?q=htaccess+rewriterule

bokeh
04-19-2007, 04:53 AM
http://forum.modrewrite.com/

pcthug
04-19-2007, 05:43 AM
It sounds as if there already is an active .htaccess file in your root directory. Add the following line before any other RewriteRules.
RewriteRule ^(.*)$ index.php/$1

bokeh
04-19-2007, 06:00 AM
It sounds as if there already is an active .htaccess file in your root directory. Add the following line before any other RewriteRules.
RewriteRule ^(.*)$ index.php/$1
That looks to me like it will cause an infinite loop.

pcthug
04-19-2007, 08:18 AM
Overlooked that, try:

RewriteRule !^(index\.php/)(.*)$ index.php/$2

bokeh
04-19-2007, 09:27 AM
Overlooked that, try:

RewriteRule !^(index\.php/)(.*)$ index.php/$2
Another way to put on the brakes would be to check if it is an internal or external request:# if it is an internal redirect
RewriteCond %{ENV:REDIRECT_STATUS} !^$
# do nothing
RewriteRule .* - [L]