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


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

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

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]

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


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

1 answer


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:

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:

Apache serves this URL (transparently):
answered by 13.03.2018 / 10:49