-3

I have dynamic pages in php like:

http://www.example.com/page.php?tokenid=1&tokenname=About Us

I want to remove this part:

.php?tokenid=1&tokenname=About Us

page extension with query string and show the url as:

http://www.example.com/About Us

Update:

What I've tried so far:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME}.php -f
    #RewriteRule ^([a-zA-Z0-9\._-]*)?/(.*)$ $1.php [QSA,E=PATH_INFO:/$2,L]
    RewriteRule ^([a-zA-Z0-9\._-]*)?/(.*)$ $1.php/$2 [QSA,E=PATH_INFO:/$2,L]
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php [QSA,L]

    # Fix PHP Authentication with FastCGI mode
    RewriteCond %{HTTP:Authorization} !''
    RewriteRule .*php - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
EhsanT
  • 2,077
  • 3
  • 27
  • 31
  • Have you tried anything? – EhsanT Dec 31 '16 at 07:48
  • @EhsanT yes i have tried lot of things from google but acutaully could not find the suitable solution. – Shrish Pulkit Dec 31 '16 at 08:20
  • So if you have tried anything, when you are posting your question, please include your code(whatever you have tried) – EhsanT Dec 31 '16 at 08:30
  • @EhsanT i have tried this code: – Shrish Pulkit Dec 31 '16 at 09:12
  • @EhsanT i have tried this code: RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME}.php -f #RewriteRule ^([a-zA-Z0-9\._-]*)?/(.*)$ $1.php [QSA,E=PATH_INFO:/$2,L] RewriteRule ^([a-zA-Z0-9\._-]*)?/(.*)$ $1.php/$2 [QSA,E=PATH_INFO:/$2,L] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [QSA,L] # Fix PHP Authentication with FastCGI mode RewriteCond %{HTTP:Authorization} !'' RewriteRule .*php - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] – Shrish Pulkit Dec 31 '16 at 09:13
  • You can get some ideas from [this answer](http://stackoverflow.com/a/41325447/1908331). But your question was somehow misleading and that was the reason the answer @sepehr provided did not solve your problem. – EhsanT Dec 31 '16 at 21:07

1 Answers1

2

Try this in your .htaccess file:

RewriteEngine on
RewriteBase /

# Skip actual files/directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# If the host matches example.com
RewriteCond %{HTTP_HOST} ^www\.example\.com$
# And the request URI starts with page.php
RewriteCond %{REQUEST_URI} ^\/page\.php
# And the querystring matches tokenid=DIGIT&tokenname=TOKEN_NAME
RewriteCond %{QUERY_STRING} tokenid=\d&tokenname=(.*)
# Then rewrite the URI to TOKEN_NAME
RewriteRule ^(.*)$ %1? [L,R]

You might want to try it online, if you wish.

enter image description here

sepehr
  • 17,110
  • 7
  • 81
  • 119
  • i have tried your suggestion, but i am getting error 404 page, i am not able to retrive the page content. – Shrish Pulkit Dec 31 '16 at 08:19
  • As far as the apache's rewrite module is concerned, you're correctly redirecting to `/About Us` page. You need to make sure that the URI actually exists. Adding a rewrite rule does not magically make that page available. – sepehr Dec 31 '16 at 08:22
  • yes but i am fetching the page from database based on tokenid and tokenname and i am rewriting the url so that the user does not see the extra query string . – Shrish Pulkit Dec 31 '16 at 08:31