Skip to content
Advertisement

How should I write the rule so that it looks like this?

I’m trying to figure out how to convert url. It leads to the index page.

the constant I define define("URL_PAGE", "page.php?p=");

link: <a class="menu-link" href="'.BASE_URL.URL_PAGE.$row1['page_slug'].'">';

.htaccess RewriteRule ^page/(.*)$/?$ page.php?p=$1 [NC,L]

result: http://localhost/aione/page.php?p=about-us

I’m trying to catch the incoming link like this.

JavaScript

How should I write the rule so that it looks like this? Your help is appreciated. http://localhost/aione/page/about-us

Advertisement

Answer

This seems to be a trivial question.

Try this:

JavaScript

Or, you can try this instead:

JavaScript

Your .htaccess file needs to look something like this:

JavaScript

Place .htaccess in the same directory (i.e. folder) as page.php. (e.g. in http://localhost/aione/)

Notes:

  • ^/*page/([^/]*)$ page.php?id=$1 only works with the following style: “http://localhost/aione/page/about-us”, if you want something like about-us/test to also be passed as page.php?id=about-us/test, use the following rule:

  • ^/*page/(.*)$ page.php?id=$1 also matches for something like “http://localhost/aione/page/about-us/test/link”, and it will rewrite to: page.php?id=about-us/test/link, meaning the following:

JavaScript

as always, remember to validate and sanitize any user input.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement