UnkwnTech
UnkwnTech

Reputation: 90831

htaccess trouble

I have this .htaccess file, which is not working, when I navegate to gotgage.local/category/gages/ the gages portion of this is not being passed

RewriteEngine On
RewriteRule     ^/category/(.*?)/$  category.php?p=$1 [rn]

For the sake of testing the category.php file is just dumping $_POST, $_GET and $_SERVER this is what I am seeing when I open the page.

GET
Array ( )
POST
Array ( ) 
SERVER
Array (
    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.59 Safari/525.19
    [HTTP_ACCEPT_ENCODING] => gzip,deflate,bzip2,sdch
    [HTTP_ACCEPT] => text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    [HTTP_CACHE_CONTROL] => max-age=0
    [HTTP_ACCEPT_LANGUAGE] => en-US,en
    [HTTP_ACCEPT_CHARSET] => ISO-8859-1,*,utf-8
    [HTTP_HOST] => gotgage.local
    [HTTP_CONNECTION] => Keep-Alive
    [PATH] => /usr/local/bin:/usr/bin:/bin
    [SERVER_SIGNATURE] =>  Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.2 with Suhosin-Patch Server at gotgage.local Port 80


    [SERVER_SOFTWARE] => Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.2 with Suhosin-Patch
    [SERVER_NAME] => gotgage.local
    [SERVER_ADDR] => 192.168.0.180
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 192.168.0.196
    [DOCUMENT_ROOT] => /home/gotgage/www/
    [SERVER_ADMIN] => [no address given]
    [SCRIPT_FILENAME] => /home/gotgage/www/category.php
    [REMOTE_PORT] => 56793
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => 
    [REQUEST_URI] => /category/gages/
    [SCRIPT_NAME] => /category.php
    [PATH_INFO] => /gages/
    [PATH_TRANSLATED] => /home/gotgage/www/gages/
    [PHP_SELF] => /category.php/gages/
    [REQUEST_TIME] => 1241579116
    [argv] => Array
        (
        )

    [argc] => 0 )

Technically the redirect is working however I am not getting the vars the page below that is dumping is the correct from the correct page but my vars are not being passed.

Upvotes: 1

Views: 832

Answers (3)

Joseph Pecoraro
Joseph Pecoraro

Reputation: 2876

Well, the following worked for me. It looks like it didn't like the leading / and the [rn] threw syntax errors for me.

RewriteEngine On
RewriteRule ^category/(.*?)/$ category.php?p=$1

Note: that it should probably have been [R,N] anyways, but again, they are not needed in this case.


RewriteRule Flags Documentation - Shows why you probably didn't want to use R or N, but there may be something we don't know.
RewriteRule Documentation - Seems to indicate no leading / in .htaccess RewriteRules (if there is a RewriteBase). Either way, try the Rule with and without the /, for me it only worked without.

Upvotes: 1

johnvey
johnvey

Reputation: 5151

There are a couple things that are somewhat unclear:

1) What was the intended match with the regex portion:

(.*?)

That is a little redundant -- assuming that you simply want to match anything between the slashes, the following would suffice:

(.*)

2) You set a flag of 'rn', which doesn't appear to be valid. Example of valid flags are:

[R]
[N]
[R,N]

though, I'm not sure you'd really want to use R and N together.

Upvotes: 0

Chad Birch
Chad Birch

Reputation: 74518

I'm not totally sure that this is the problem, but putting the flags as "[rn]" is not valid. Multiple flags should be separated with commas, so if you're trying to put both the R and N flags, it should be [R,N]

Upvotes: 0

Related Questions