How to get last part of URL to process in parent directory without creating a new child directory

Viewed 52

I have a url similar to:

https://example.com/event/FI42382

I have created a folder named event from which I want to use PHP to process the FI42382 part.

However, the last part is treated as its own directory. What do I need to do so that it is not a directory and instead I can manipulate the last path as a variable in event/index.php?

Sorry if I have worded the title poorly. I wasn't sure how to explain this.

1 Answers

You need to pass value which you want to access through a query string to your index.php etc. In your .htaccess file try with following Rules once. Also make sure place your .htaccess file in root(same level along with your event folder is present, NOT inside event folder please). Later in your php code you could get/extract the var value which is passed to it.

Please make sure you clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteRule %{QUERY_STRING} ^$
RewriteRule ^event/(.*)/?$ event/index.php?var=$1 [NC,L]
Related