I am looking to rewrite
http://domain.com/zzz-zzz/?source=[variable1]&referrer=[variable_2]
to
http://domain.com/xxx-xxx/?source=[variable1]&referrer=[variable_2]
I had done :
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^(.*)zzz-zzz(.*)$
RewriteRule ^$ ?xxx-xxx%2 [R=301,L]
The QUERY_STRING does not include the path and script file (zzz-zzz/). That would be the REQUEST_URI. The QUERY_STRING would be source=variable1&referrer=variable2. If all you want to do is change zzz-zzz to xxx-xxx:
RewriteEngine On
RewriteBase /
RewriteRule ^zzz-zzz/?(.*)$ /xxx-xxx/$1 [R=301,L]
ought to get you close. The entire Query String should be brought over.
Related
I have URL domain.com/index.php
I have written this code to redirect to clientarea.php
RewriteEngine On
RewriteRule ^index.php /clientarea.php [R=301]
Now this works except for urls that contain a query string (eg. domain.com/index.php?=something). This will also redirect but I don't want it when there is a query string.
Can anyone tell me how I can do it ?
To prevent rewriting when a query string is there
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index\.php$ /clientarea.php [R=301,L]
RewriteEngine On
RewriteRule ^index.php$ /clientarea.php? [R=301]
$ marks the end of the string in the regex.
Using htaccess or any other way how can I pass a parameter to end of url suffix
EX: I need all the .html to be html?v=1
I tried the following
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.html$ $1.html?v=1 [R]
But Its not working
Check first that the query string does not already exist:
RewriteEngine On
RewriteCond %{QUERY_STRING} !v=1
RewriteRule ^(.*)\.html$ $1.html?v=1 [R,L]
I'm trying to redirect to the base url (www.example.com) requests that have a particular query string (when option is com_estateagent).
I've tried the following syntax:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^option=com_estateagent$
RewriteRule .* index.php [R=301, L]
But it gets ignored.
Any suggestions?
EDIT
The url that I want to change is something like this:
http://www.example.com/subdirectory/index.php?option=com_estateagent...
I don't think you need the RewriteCond directive, wouldn't something like this work?
RewriteRule ^/.*option=com_estateagent /index.php[R=301,L]
This works
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} option=com_estateagent
RewriteRule .* subdirectory/index.php? [R=301, L]
Notice, the ? after index.php. That's important if you want to drop Query Parameters on redirect.
I'd like to remove the ?sid=123456 (can be any number)
redirect: http://www.mydomain.com/directory-a/directory-b/directory-c/?sid=123456
to: http://www.mydomain.com/directory-a/directory-b/directory-c/
According to your question:
"redirect: http://www.mydomain.com/directory-a/directory-b/directory-c/?sid=123456"
"to: http://www.mydomain.com/directory-a/directory-b/directory-c/"
This one way to do it:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} sid=\d+.*
RewriteRule .* %{REQUEST_URI}? [L,R=301]
In short, what the rule does is removing the query string which is what the question is asking for.
Try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^sid=[0-9]+&?(.*)$
RewriteRule ^(.*)$ /$1?%1 [L,R=301]
I would like to redirect mysite.com/index.php to mysite.com/index.php?id_category=12&controller=category
Here is my htaccess file.
But it doesn't work. Chrome says : This webpage has a redirect loop.
Options +FollowSymLinks +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
RewriteRule index\.php http://mysite.com/index.php?id_category=12&controller=category
This should work:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/index.php$
RewriteCond %{QUERY_STRING} ^$
RewriteRule (.*) http://www.mywebsite.com/index.php?foo=bar [R=301,L]
The first condition checks if the URI is equal to index.php and the second one checks if GET values are empty. The AND between the 2 conditions is implicit here.
Probably you should change use another file name instead of index.php for the destiny. But you can try:
RewriteRule index.php index.php?id_category=12&controller=category