Yasir Parvez
Yasir Parvez

Reputation: 21

Can't access post or get from a php page after redirecting

I'am redirecting about 100 hmtl pages to a single PHP page (example.php) using .htaccess. It is working perfectly.

I've pagination on that page (example.php) but I am using the original HTML page URL (example.html?page=2&limit=20)

  1. so example.html, example1.html, example2.html, example3.html are all redirecting to example.php.
  2. The address bar is still showing ".html" URL but due to .htaccess redirection the example.php is rendering.
  3. when is click on a pagination link (example.html?page=2&limit=20) the browser address bar shows correct .html URL and query string.
  4. I've tried to get the values of page, and limit using $_GET and $_REQUEST in (example.php) but i am not successful.

Please help me in reading the (example.html?page=2&limit=20) query string parameeters .

Edit Code ported from comments:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !^page-(.*)$
RewriteRule ^page-(.*)$ size-content.php?sef=$1 [L]

Upvotes: 2

Views: 181

Answers (3)

Muhammad Majid Saleem
Muhammad Majid Saleem

Reputation: 25

Yasir - you can resolve this problem by two ways: 1) Re-write rules for .htaccess

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !^page-(.).html(.)/(.)$ RewriteRule ^page-(.).html(.)/(.)$ size-content.php?sef=$1&page=$2&limit=$3 [L]

This rule will handle: page-example.html?page=2&limit=20

I hope - you will easily understand the above rule.

Note: Keep one thing in your mind that every link should be in same pattern if you change rule in htaccess.

2) You can resolve this problem on your "size-content.php"

Suppose page-example.html?page=2&limit=20

$_GET['sef'] = example.html?page=2&limit=20 [according to you .htaccess]

Now you can parse this string via explode function

Thanks

Upvotes: 0

Michael Berkowski
Michael Berkowski

Reputation: 270637

Add the QSA flag, which means "query-string append" to be sure the existing query string is ported into the rewritten URL.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !^page-(.*)$
RewriteRule ^page-(.*)$ size-content.php?sef=$1 [L,QSA]

Upvotes: 3

Achiles
Achiles

Reputation: 122

.htaccess modify your server configuration.

if you are making redirection then you change your request. Try mod_rewrite if you are using Apache of course.

RewriteEngine On
RewriteRule ^example\.html\?(.*) example.php?$1

Mod rewrite is module to Apache. It is not allowed on most free hostings.

Upvotes: 0

Related Questions