I have PHP file page.php
, and with this file I dynamically change content. So how can I make with htaccess to change link from www.example.com/page.php?page=somepage
to www.example.com/somepage
?
Asked
Active
Viewed 2,108 times
1

Clashsoft
- 11,553
- 5
- 40
- 79

fr33jumper
- 103
- 3
- 13
-
Possible duplicate of [Rewriting an arbitrary number of path segments to query parameters](http://stackoverflow.com/questions/3655893/rewriting-an-arbitrary-number-of-path-segments-to-query-parameters) – Quentin Nov 23 '15 at 15:31
-
2Note that you don't change a URL _from_ `/page.php?page=somepage` to `/somepage` in .htaccess. This is something you do in your application. However, you can implement an external redirect to handle _old_ URLs if you wish. What you do do in .htaccess is _internally rewrite_ the request from `/somepage` to `/page.php?page=somepage` (ie. the other way round) - as Starkeen has covered in his answer. – MrWhite Nov 23 '15 at 15:38
1 Answers
0
Add the following code to your htaccess file :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /page.php?pape=$1 [NC,L]
This will rewrite your url
example.come/somepage
to
example.come/page.php?page=somepage

Amit Verma
- 40,709
- 21
- 93
- 115