1

So far I have learnt RewriteRule ^([^/]*)/$ index.php?page=$1

Problem 1: How do I parse the url parameters as they are after a point certain point?

E.g. I want this page http://example.com/index.php?page=X&id=2&err=10 to appear as http://example.com/X/?id=2&err=10. Given that the parameters id or err necessarily do not exists. They may or may not be present with others.

Problem 2: For some specific pages suppose page=A or page=B, if id exists, there will be a third parameter as well.

E.g. I want this page http://example.com/index.php?page=A&id=10&name=Abe to appear as http://example.com/A/Abe/10/ and http://example.com/index.php?page=A&id=10&name=Abe&err=101 to appear as http://example.com/A/Abe/10/?err=101

Edit 30 Jan, 16

Ok. After much searching I found that it could be implemented by using {QUERY_STRING}. But when I place RewriteRule ^([^/]*)$ index.php?page=$1&%{QUERY_STRING} [NC,L] in my htaccess my Ajax goes haywire. I want this working to implement only for index.php and no other pages.

URL Rewrite GET parameters

Community
  • 1
  • 1
abhig10
  • 535
  • 7
  • 24

1 Answers1

0

Using RewriteCond rule I was able to solve problem 1, however, I am yet to implement it for problem 2.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ index.php?page=$1&%{QUERY_STRING} [NC,L]

Solved Problem 2 as well:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^A/([^/]*)/([^/]*)/$ index.php?page=A&id=$1&z=$2&%{QUERY_STRING} [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^B/([^/]*)/([^/]*)/$ index.php?page=B&id=$1&z=$2&%{QUERY_STRING} [NC,L]

Note: For some reason using this (below) lines caused the mess. Removing the comment from them works fine.

RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*)$ index.php?page=$1&%{QUERY_STRING} [NC,L]
abhig10
  • 535
  • 7
  • 24