Reputation: 79
How can I convert URL from:
http://example.com/site/delete-page.php?site=first&page=second
To:
http://example.com/site/first/delete-page/second
Thank You!
Upvotes: 1
Views: 2609
Reputation: 42885
This is the normal rule for that specific task:
RewriteEngine on
RewriteRule ^/site/([^/]+)/delete-page/(.+)$ /site/delete-page.php?site=$1&page=$2 [L]
To use the same rule inside a .htaccess
style file you have to modify it slightly: remove the leading slash (/
) from pattern and target:
RewriteEngine on
RewriteRule ^site/([^/]+)/delete-page/(.+)$ site/delete-page.php?site=$1&page=$2 [L]
This assumes that the .htaccess
style file is located inside the folder holding the site
folder. You can also place the file inside that site
folder, then obviously you have to remove the site/
part from the rules pattern and target. Also you have to take care that the interpretation of .htaccess
style files is enabled at all for that host and location.
In general you should always prefer the first version and place such rules inside your http servers host configuration. .htaccess
style files are notoriously error prone, hard to debug and they really slow the server down. They are only offered as a last option for situations where you do not have access to the server configuration. For example when using a really cheap shared web hoster service...
Upvotes: 3