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.
Assumptions:
- You are already linking to the URL without the
/portal
prefix in your internal links.
- There are no other
.htaccess
files in any of the subdirectories (eg. /portal
or /portal/reports
)
- Using Apache 2.4 (as opposed to Apache 2.2).
portal
folder, not thereports
folder? Please include what you have tried and the contents of your existing.htaccess
file.