Friendly URLs, remove / replace parts of a .htaccess URL

1

I have this url to access a study on the web:

http://miweb.com/index.php?option=com_component&view=estudio&factura=1&id=25977&token=8f8c54a3ce165332fd59f17

I want a URL similar to the following, redirect to the previous one

http://miweb.com/estudio&factura=1&id=25977&token=8f8c54a3ce165332fd59f17

That is, replace a part of the URL, but keep the other parameters.

So far, I have edited mod_rewrite from the .htaccess file and managed to replace strings (for example com_component ), but not the string index.php?option=com_component&view=estudio . This gives me an error, will it be for ?&= ?

RewriteEngine On
Rewritebase /

<IfModule mod_rewrite.c>
    RewriteCond %{QUERY_STRING} (.*)com_component(.*) [NC]
    RewriteRule (.*) $1?%1nuevostring%2 [R=302,L]
</IfModule>

How can I replace the entire line index.php?option=com_component&view=estudio with a word (eg "study")?

Edit:

Is it possible that the URL will use the URL with all the parameters, but that the part of index.php?option=com_component&view=estudio does not appear? I do not want the user to see the option and view name, but instead they are parameters that I need for the URL to work

    
asked by Norak 12.03.2018 в 11:49
source

1 answer

2

First of all, notice that you have an error in the URL. The parameters always start with ? and separate with & . The URL to which the end user will access is going to be:

http://miweb.com/estudio?factura=1&id=25977&token=8f8c54a3ce165332fd59f17

What you're looking for is a rewrite (no redirection), which involves taking a URL and serving a different resource (rewritten), but without modifying the client's URL (without redirecting), so transparent for this one.

That is, we would have the redirection that is already in your rules to modify a parameter, and we would add this rewrite:

RewriteEngine On
Rewritebase /

# Redireccionar para eliminar el parámetro de la URL
RewriteCond %{QUERY_STRING} ^(.*[&?]option=)com_component((?:[&?]|$).*) [NC]
RewriteRule (.*) $1?%1com_newname%2 [R=302,L]

# Reescritura de /estudio  a  index.php?option=com_component&view=estudio
RewriteRule ^estudio$ index.php?option=com_component&view=estudio [NC,QSA,L]

Thus, when the client accesses:

http://miweb.com/estudio?factura=1&id=25977&token=8f8c54a3ce165332fd59f17

Apache serves this URL (transparently):

http://miweb.com/index.php?option=com_component&view=estudio&factura=1&id=25977&token=8f8c54a3ce165332fd59f17
    
answered by 13.03.2018 / 10:49
source