Reputation: 2851
Let's say I have this URL: http://mydomain.com/app/editor/?id=59500
I would like to have this url to instead show the following in the browser address bar: http://mydomain.com/app/editor/59500
...but have the PHP page ("http://mydomain.com/app/editor/index.php") remain the same. In otherwords, I still want to have this page to be able to execute $_GET['id']; and return "59500".
Would I use regex in HTACCESS for this? Any advice on the best approach and an example would be greatly appreciated.
Upvotes: 0
Views: 24
Reputation: 143906
Try adding these rules to the htaccess file in the /app/editor/
directory:
RewriteEngine On
RewriteBase /app/editor/
RewriteCond %{THE_REQUEST} \ /+app/editor/(index\.php)?\?id=([0-9]+)
RewriteRule ^ %1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/?$ index\.php?id=$1 [L]
Upvotes: 0
Reputation: 132
You want to use a .htaccess rewrite for this. You can make the redirect happen only when the URL ends with a number (to avoid redirecting index.php).
The \d+
gets all digits, and the /?
will allow URLS that either have a slash after the ID or not.
Something like:
<ifmodule mod_rewrite.c>
RewriteRule ^app/editor/(\d+)(/?)$ app/editor/index.php?id=$1
</ifmodule>
Upvotes: 1