Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Website and Server Administration Forum


You are currently viewing our Website and Server Administration Forum as a guest. Please register to participate.
Login



Reply
mod_rewrite weirdness
Old 03-04-2010, 03:27 PM mod_rewrite weirdness
Novice Talker

Posts: 6
Trades: 0
Hi,

this is my test.php
PHP Code:
echo $_GET['seite']; 
when my .htaccess file looks like this:
PHP Code:
RewriteEngine on
RewriteRule 
^(.*)\.htmltest.php?seite=$[L
and i type "foobar.html" in the browser it shows me the word foobar.
Ok, that works!

but if i use this .htaccess file:
PHP Code:
RewriteEngine on
RewriteRule 
^(.*)\.phptest.php?seite=$[L
and type "foobar.php" it gives me "test" instead of "foobar".
Hmm ... Why?

For SEO reasons i have to keep the php ending.
So why does this example work with html ending but not with php ending?

thanks in advance,
manitwo
manitwo is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-05-2010, 08:09 AM Re: mod_rewrite weirdness
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
I guess I redirect to times
First time
Code:
from foobar.html to test.php?seite=foobar
Second time
Code:
from test.php?seite=foobar to test.php?seite=test
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 03-05-2010, 09:44 AM Re: mod_rewrite weirdness
Novice Talker

Posts: 6
Trades: 0
unfortunatly i can't say i fully understand your reply.
do you mean it does redirect two times or you would redirect two times?
my goal is to show the site as "foobar.php" but handled internaly as "index.php?seite=foobar".
i can't wrap around my head around why this doesn't work as in my example in post 1.

nevertheless thanks for your answer

cheers,
manitwo
manitwo is offline
Reply With Quote
View Public Profile
 
Old 03-06-2010, 11:47 PM Re: mod_rewrite weirdness
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
RewriteRule test.php - [L]
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 03-07-2010, 04:39 AM Re: mod_rewrite weirdness
Novice Talker

Posts: 6
Trades: 0
Quote:
Originally Posted by mtishetsky View Post
RewriteRule test.php - [L]
what is this supposed to do?
i added this line in my htaccess file but got a 404 when i tried to reach "foobar.php".

thanks,
manitwo
manitwo is offline
Reply With Quote
View Public Profile
 
Old 03-07-2010, 04:51 AM Re: mod_rewrite weirdness
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
It should prevent test.php from being rewritten to itself. And this rule should be inserted BEFORE the existing one.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 03-07-2010, 05:06 AM Re: mod_rewrite weirdness
Novice Talker

Posts: 6
Trades: 0
alright, thanks for your fast reply.
foobar.php($_GET['seite']) outputs "test" instead of "foobar".
whereas foobar.php should be handled as test.php?seite=foobar so obviously the word "foobar" should be saved in "seite" variable not "test".
i don't understand whats going on.

here's my htaccess with your correction:
PHP Code:
RewriteEngine on
RewriteRule test
.php -
RewriteRule ^(.*)\.phptest.php?seite=$[L
manitwo is offline
Reply With Quote
View Public Profile
 
Old 03-07-2010, 05:14 AM Re: mod_rewrite weirdness
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Where is [L] from my "test.php -" line?

To understand what's going on you should first understand how does mod_rewrite work, and only then try to do tricks with it.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 03-07-2010, 05:35 AM Re: mod_rewrite weirdness
Novice Talker

Posts: 6
Trades: 0
thank you very much mtishetsky.
now it works.
sorry for removing the [L] but i thought i read somewhere that this indicates the last rule. my bad

thanks for your time and your help!
manitwo
manitwo is offline
Reply With Quote
View Public Profile
 
Old 03-07-2010, 07:27 AM Re: mod_rewrite weirdness
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,390
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
The [L] flag indicates the last rewrite rule for that request NOT the last necessarily the last rule in the file.
Apache then starts a new request for the rewritten filenames which will process htaccess again.

This behaviour ONLY applies to .htaccess BTW for httpd.conf the [L] flag does indicate the last rule to be applied for that rewrite condition.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-07-2010, 07:56 AM Re: mod_rewrite weirdness
Novice Talker

Posts: 6
Trades: 0
Quote:
Originally Posted by chrishirst View Post
The [L] flag indicates the last rewrite rule for that request NOT the last necessarily the last rule in the file.
Apache then starts a new request for the rewritten filenames which will process htaccess again.

This behaviour ONLY applies to .htaccess BTW for httpd.conf the [L] flag does indicate the last rule to be applied for that rewrite condition.
thanks for clearing that up chrishirst
manitwo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to mod_rewrite weirdness
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 2.37577 seconds with 12 queries