In this URL I want to hide portal folder in the url/:


How can I achieve this using mod_rewrite?

I used online generators and Researched in Many Stack Website for doing the rewrite rules but none can remove a piece of text from the URL But None Worked For Me

  • "I want to hide reports folder" - In your example you appear to have hidden the portal folder, not the reports folder? Please include what you have tried and the contents of your existing .htaccess file.
    – MrWhite
    Commented Mar 5, 2023 at 13:40
  • Yea I Wanna Hide the portal folder , Modified The Question !
    – Ram Gowda
    Commented Mar 5, 2023 at 14:33
  • But what have you tried Commented Mar 5, 2023 at 18:52
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Mar 5, 2023 at 18:53

1 Answer 1


To permanently "remove" the /portal prefix from the stated URL, you could do something like the following in the root .htaccess file using mod_rewrite:

RewriteEngine On

# Remove "/portal" prefix from stated URL
RewriteCond %{QUERY_STRING} ^id=2$
RewriteRule ^portal/(reports/data\.php)$ /$1 [R=301,L]

# Rewrite the request back to the actual file
RewriteCond %{QUERY_STRING} ^id=2$
RewriteRule ^reports/data\.php$ portal/$0 [END]

The $0 and $1 backreferences refer back to the captured groups in the preceding RewriteRule pattern. $0 refers to the entire match.

The query string (ie. id=2) is passed through by default.


  1. You are already linking to the URL without the /portal prefix in your internal links.
  2. There are no other .htaccess files in any of the subdirectories (eg. /portal or /portal/reports)
  3. Using Apache 2.4 (as opposed to Apache 2.2).
  • I Have Tried This Similar Its Not Working !
    – Ram Gowda
    Commented Mar 7, 2023 at 14:17
  • @RamGowda What do you mean by "Similar"? What do you mean by "Not Working" exactly? Are you getting an error? Undesirable response? Nothing? What URL are you requesting? What other directives do you have in the .htaccess file? Do you have any other .htaccess files in subdirectories? What version of Apache are you using? Is this your own local development server or a cloud/live server? Do you have access to the main server config?
    – MrWhite
    Commented Mar 7, 2023 at 17:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.