-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> 
6
  • Have you tried anything? Commented Dec 31, 2016 at 7:48
  • @EhsanT yes i have tried lot of things from google but acutaully could not find the suitable solution. Commented Dec 31, 2016 at 8:20
  • So if you have tried anything, when you are posting your question, please include your code(whatever you have tried) Commented Dec 31, 2016 at 8:30
  • @EhsanT i have tried this code: Commented Dec 31, 2016 at 9:12
  • @EhsanT i have tried this code: <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> Commented Dec 31, 2016 at 9:13

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

i have tried your suggestion, but i am getting error 404 page, i am not able to retrive the page content.
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.
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 .

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.