I need to rewrite the following url:
mydomain.com/dashboard/index.php?user=john-dow
to
john-dow.mydomain.com/dashboard/index.php
So I want to take the query string value and place it at the beginning of my domain followed by a dot. The goal is to create a customized user url, so it looks very friendly to users. But actually, I don't know how can I do that. Is it possible by .htaccess? If yes, how?
Use in your dashboard/.htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(.+)\.mydomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^user=(.+)$
RewriteRule ^index\.php$ http://%1.mydomain.com/dashboard/index.php? [R,L]
Related
Here is a sample old URL:
https://www.olddomain.com/index.php?option=com_k2&view=itemlist&task=calendar&month=8&year=1904&catid=39&Itemid=339
Which needs to be redirected to:
https://www.newdomain.com/index.php?option=com_k2&view=itemlist&task=calendar&month=8&year=1904&catid=39&Itemid=339
Since there are countless month,year,catid,and itemid I wanted to catch them all with one rule.
I was trying to create a htaccess redirect for any URL that has "/index.php?option=com_k2&view=itemlist&task=calendar".
This was my best attempt:
RewriteEngine on
RewriteRule ^/index.php?option=com_k2&view=itemlist&task=calendar(.*)$ https://www.newdomain.com/index.php?option=com_k2&view=itemlist&task=calendar$1 [R=301,L]
You may be able to use this redirect rule:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^option=com_k2&view=itemlist&task=calendar [NC]
RewriteRule ^ https://newdomain.com%{REQUEST_URI} [R=301,L,NE]
Make sure this your topmost rule and you refresh your browser cache before testing this rule.
I try to write a RewriteRule in the .htaccess but I have problems
I try to redirect from:
blog/entrada.php?id=2
To:
/blog/3D-touch
This is one of the multiple things I tried and does not work:
RewriteRule ^blog\/entrada\.php\?id=2$ /blog/3D-touch [L,R=301]
What is wrong with my Rule. How to redirect effectively?
Thanks
Querystring is not part of match in RewriteRule directive, to redirect query strings, you need to use RewriteCond one of the following options :
option 1
RewriteEngine on
RewriteCond %{THE_REQUEST} /blog/entrada\.php\?id=2 [NC]
RewriteRule ^ /blog/3D-touch? [NC,L,R]
option 2
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=2$ [NC]
RewriteRule ^blog/entrada\.php$ /blog/3D-touch? [NC,L,R]
We use an empty question mark ? at the end of the target url to discard the old query strings, otherwise these query strings get appened to the target url by default.
Change the R to R=301 if you want to make the redirection permanent.
use from this code
RewriteRule blog/(.*) blog/entrada.php?id=$1
this code will redirect all urls which have blog/ to blog/entrada.php and put after value of blog/ to $_GET['id']
you should have following code n the top location of your htaccess file
Options +FollowSymLinks
RewriteEngine on
Our original urls began with a parameter and the following rewrite works to redirect them (thanks to Jon Lin).
However, the original parameter is being appended to redirect, so that
RewriteEngine On
RewriteCond %{QUERY_STRING} ^old-page$
RewriteRule ^$ /newpage [R=301,L]
ends up going to mydomain.com/newpage?old-page
Any idea how to fix? thanks again,
Geoff
Have it like this to strip off existing query string:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^old-page$ [NC]
RewriteRule ^$ /newpage? [R=301,L]
Take note of ? at the end of target URI, that is used to strip-off existing query string.
I tried the below .htaccess rewrite to internally rewrite the urls and make the overall urls SEF.
RewriteCond %{QUERY_STRING} ^searchword=(.*)&(.*)$ [NC]
RewriteRule ^searchword=(.*)&(.*)$ searchword=$1 [L]
My url is of the following form.
http://www.domain.com/?searchword=search+term&Search=&searchphrase=all&limit=50&ordering=newest&view=search&option=com_search
I want to make it of the form
http://www.domain.com/?searchword=search+term
You can use this rule:
RewriteCond %{QUERY_STRING} ^(searchword=[^&]+)$ [NC]
RewriteRule ^ /?%1&Search=&searchphrase=all&limit=50&ordering=newest&view=search&option=com_search [L,NE]
The best way to do this is by adding a router.php file to your component. Take a look at http://docs.joomla.org/Supporting_SEF_URLs_in_your_component
I'm looking for an Apache Rewrite Condition that fires if a certain URL parameter is not set and then rewrites the URL by adding this parameter.
So basically if my URL looks like http://www.heco.de/index.php?id=123&catId=456, I want it to redirect to http://www.heco.de/index.php?id=123&catId=456&cHasH=456
The first parameter is a static page ID, but the catId varies from a single digit up to 6 digits.
I tried to achieve this by adding this code snippet to my .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} catId=([0-9]{1,6})
RewriteCond %{QUERY_STRING} !cHash=
RewriteRule ^(.*)/?id=123&catId=([0-9]{1,6})$ index.php?id=123&catId=$2&cHash=$2
#RewriteRule ^(.*)/?id=123&catId=([0-9]+)$ http://www.stackoverflow.com
Alas, it's not working. I tried testing this by uncommenting the last line, but no redirect takes place at all. Hence I would be really grateful for any insights, ideas or further advice...!
Thx in advance,
Martin
You can't match QUERY_STRING in RewriteRule.
You can use this rule:
RewriteCond %{QUERY_STRING} !(?:^|&)cHash=[^&]+ [NC]
RewriteCond %{QUERY_STRING} (?:^|&)catId=([0-9]{1,6}) [NC]
RewriteRule ^index\.php$ $0?cHash=%1 [L,QSA,NC]