0

I have limited .htaccess knowledge and i am requiring some help. I need to do some redirects to enable pretty urls. In local all works fine but it is not working in another develpment server. apparently the query string get drop when redirect. i need to redirect this http://mysite.local/info/permalink/1

to this one http://mysite.local/info?proxy=true&id=1

my .htaccess code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#remove /index.php from home url and redirect to root.
#http://mysite.local/index.php -> http://mysite.local/ 
RewriteCond %{THE_REQUEST} ^.*\/index\.php?\ HTTP/
RewriteRule ^(.*)index\.php?$ "/$1" [R=301,L,QSA]

#pretty url without index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [PT,QSA,L]

#rewrite to handle some permalink saved on my db.
#http://mysite.local/info/permalink/1
#http://mysite.local/info/proxy=true&id=1
RewriteRule ^([^/]+)/info/([a-zA-Z0-9\-]+)/([0-9]+) /info/?proxy=true&id=$3 [L]
</IfModule>

the redirect is working but the query string is not present. When I run var_dump($_GET) on info module i am getting an empty array array(0) {} i have try it to solve changing

RewriteRule .* index.php [PT,QSA,L]

to RewriteRule ^(.*)$ /%{QUERY_STRING} [L]

and

RewriteRule ^([^/]+)/info/([a-zA-Z0-9\-]+)/([0-9]+) /info/?proxy=true&idobj=$3 [L]

to

RewriteRule ^([^/]+)/info/([a-zA-Z0-9\-]+)/([0-9]+) /info/?proxy=true&idobj=$3 [QSA,NE,L]

Server API is CGI/FastCGI

What should I change to ensure that my rewrite works as intended and $_GET variables still are accessible? thx in advance

1 Answer 1

1

I have no idea how you've managed to get this to work with a regex pattern like: ^([^/]+)/info if the URL you are going to is /info/permalink/1.

The ^([^/]+)/info pattern means there's stuff before the /info part of the URI, which there isn't. Additionally, in an htaccess file, the URI's have the leading forward slash stripped off. So you probably want something like this:

RewriteRule ^info/([a-zA-Z0-9\-]+)/([0-9]+) /info/?proxy=true&id=$2 [L]
Sign up to request clarification or add additional context in comments.

1 Comment

Thx about the answer. That i said, i have limited .htaccess knowledge. In my local pc my htaccess works. If I use your modification it not works. but the problem not is my machine but the testing server. Anyway in the testing server your solution still not work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.