1

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!

1
  • 1
    A general hint: such questions often receive bad feedback. The guidelines how to ask questions here clearly state two things: 1. you are expected to have a minimum understanding of the topic your question deals with and 2. you are expected to show own effort to have solved the issue before asking here... Commented Feb 12, 2016 at 23:11

1 Answer 1

3

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...

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.