Forum Moderators: phranque

Message Too Old, No Replies

I have a big problem width the index.php

         

Max134

1:40 pm on Mar 26, 2011 (gmt 0)

10+ Year Member



Hello

The index.php is allways to me the most hard part. I can read apache manual, but still I can find the right answer.

My htaccess is this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]


/* from now on, code for other pages for example */
RewriteRule ^otherpage/([0-9]+)/([0-9]+)/$ other.php?some=$1&logout=$2 [L]
RewriteRule ^otherpage/([0-9]+)/$ other.php?play=$1 [L]
RewriteRule ^otherpage/ other.php [L]


I want in index.php put a friendly url, equivalent to index.php?logout=121 , for example, so the friendly url it would be like this:
http://www.mysite.com/121/


I try something like this, but doesn't work:

[code]RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

/* what I try and it doesn't works */

RewriteRule http://www.mysite.com/([0-9]+)/ index.php?logout=$1[L]



Any idea ?

thanks in advance !

phranque

6:23 am on Mar 27, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the pattern in your RewriteRule will be matched against the "current" url which in the case of your .htaccess file will not contain the hostname or root directory slash:

RewriteRule:
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule [httpd.apache.org]

Note: Pattern matching in per-directory context
Never forget that Pattern is applied to a complete URL in per-server configuration files. However, in per-directory configuration files, the per-directory prefix (which always is the same for a specific directory) is automatically removed for the pattern matching and automatically added after the substitution has been done. This feature is essential for many sorts of rewriting - without this, you would always have to match the parent directory which is not always possible.

There is one exception: If a substitution string starts with ``http://'', then the directory prefix will not be added, and an external redirect or proxy throughput (if flag P is used) is forced!


try this:
RewriteRule ^([0-9]+)\/$ index.php?logout=$1 [L]