Skip to main content
Made it specific for the URL stated in the question, since the question does not state otherwise
Source Link
MrWhite
  • 43.1k
  • 4
  • 50
  • 90

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:

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

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:

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

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:

  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).
 
Post Undeleted by MrWhite
Made it specific for the URL stated in the question, since the question does not state otherwise
Source Link
MrWhite
  • 43.1k
  • 4
  • 50
  • 90

InTo 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]
RewriteRule
# ^Rewrite portal%the request back to the actual file
RewriteCond %{REQUEST_URIQUERY_STRING} ^id=2$
RewriteRule ^reports/data\.php$ portal/$0 [END]

This unconditionally removesThe $0 and $1 backreferences refer back to the captured groups in the preceding /portalRewriteRule prefix from everypattern URL. Including all static assets$0 refers to the entire match.

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

Assumptions:

  1. You are already linking to the URL without the /portal prefix in your internal links and links to your static assets. 
  2. There isare no other .htaccess filefiles in any of the subdirectories (eg. /portal or /portal/reports)
  3. Using Apache 2.4 (as opposed to Apache 2.2).

In the root .htaccess file using mod_rewrite:

 
RewriteEngine On

RewriteRule ^portal(?:/|$)(.*) /$1 [R=301,L]
RewriteRule ^ portal%{REQUEST_URI} [END]

This unconditionally removes the /portal prefix from every URL. Including all static assets.

Assumptions:

  1. You are already linking to the URL without /portal in your internal links and links to your static assets.
  2. There is no other .htaccess file in any of the subdirectories (eg. /portal or /portal/reports)

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:

  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).
Post Deleted by MrWhite
Source Link
MrWhite
  • 43.1k
  • 4
  • 50
  • 90

In the root .htaccess file using mod_rewrite:

RewriteEngine On

RewriteRule ^portal(?:/|$)(.*) /$1 [R=301,L]
RewriteRule ^ portal%{REQUEST_URI} [END]

This unconditionally removes the /portal prefix from every URL. Including all static assets.

Assumptions:

  1. You are already linking to the URL without /portal in your internal links and links to your static assets.
  2. There is no other .htaccess file in any of the subdirectories (eg. /portal or /portal/reports)