Mobile app version of vmapp.org
Login or Join
Megan663

: How to match only part of URL and redirect URL with parameters in .htaccess? I have a number of links with similar structure: example.com/index.php/path/some-path/some-subpath?parameter=1 Which I

@Megan663

Posted in: #301Redirect #Htaccess #ModRewrite #Redirects

I have a number of links with similar structure:

example.com/index.php/path/some-path/some-subpath?parameter=1


Which I want to redirect just to example.com/category/

But I want to match only the URL-path, ie. /index.php/path/some-path/some-subpath, because the query parameter is irrelevant.

I have tried the following rule:

RewriteRule ^/index.php/path/some-path/some-subpath?parameter=dd? /category/ [L,R=301]

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Megan663

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

If the query string is irrelevant then it can simply be ignored. (You can't match the query string anyway with the RewriteRule directive.)

Try the following in your root .htaccess file to redirect the request:

RewriteEngine On
RewriteRule ^index.php/path/some-path/some-subpath$ /category/? [L,R=301]


In per-directory .htaccess files, the URL-path matched by the RewriteRule pattern has the directory-prefix removed. In other words, it does not start with a slash, ^index.php.... instead of ^/index.php.....

The ? on the end of the RewriteRule substitution is required in order to remove the query string (if any) from the request. Otherwise parameter=1 will be passed through and appended to the target URL.

This will match any query string, including an empty one.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme