I searched for this issue but couldn't find the exact solution to my problem.
I'm trying to use QUERY_STRING to find part of a URL and then add this to the end of the redirection URL.
domain/?atid=00
domain/page/?atid=00
The '?atid=' and 'page' will always be the same but the number will change.
eg.
domain/?atid=05 domain/page/?atid=05
domain/?atid=21 domain/page/?atid=21
I think that I am on the right track with this but it currently doesn't work
RewriteCond %{QUERY_STRING} ^atid=([0-9]*)$
RewriteRule ^atid?$ aff-redirection/?atid=%1
Or if I do not actually need to use QUERY_STRING I think I would be able to use something along these lines?
RewriteRule ^atid=([0-9]+)/$ page/?atid=$1
Any help on this would be great!
RewriteCond %{QUERY_STRING} ^atid=([0-9]*)$
RewriteRule ^$ page/$1 [R=302,QSA,L]
if it is working you can change 302 to 301 to make it permanent
Related
I have searched but cannot find a specific answer for this exact redirect style...
I have this structure of URL with this specific parameter:
https://websitename.com/directory/index.php?option=com_virtuemart&view=cart
I want it redirected to:
https://websitename.com/shopping-cart/
Note that the above mentioned "directory" changes, but the index.php with the parameters stay the same. No matter what the directory is, I always want it to go to the same exact redirect.
I cannot seem to get the right redirect working in htaccess. Can anyone help?
You can use this redirect rule as your first rule in site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?option=com_virtuemart&view=cart [NC]
RewriteRule ^ /shopping-cart/? [L,R=308]
# remaining rules go below this
You can use a set like this. It takes care on the param view=cart
RewriteCond %{QUERY_STRING} (^|&)view=cart
RewriteRule ^(.*)$ /shopping-cart/? [L,NC,R=301]
If you want to keep the querystring params, then change
/shopping-cart/?
to
/shopping-cart/
without questionmark
I have a website where i have pages like:
domain.com/?p=settings
domain.com/?p=daily
And i am looking for rewrite that ?p= part, so it would be like
domain.com/settings
So far i have tried to add this to htaccess files:
RewriteRule ^([^\.]+)$ $1?p= [NC,L]
but it did not worked.
Also I have tried look from Google but could not find any.
I have tried other RewriteRule's but they did not work either.
RewriteRule does not include query string. It is available as a separate variable enter link description here
The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (e.g. "/app1/index.html"). This is the (%-decoded) URL-path.
So the following won't work.
RewriteRule ^([^.]+)$ $1?p= [NC,L]
You need something like
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule ^/ %2?
Checkout Apache Mod ReWrite Wiki and scroll down to "Making the Query String Part of the Path"
You were close with your attempt, you need to use this in your .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)$ /?p=$1 [L]
Make sure to clear your cache before testing this.
I'm try to make one trick for my webpage but I don't have any idea to make it that.
if my url is
mydomain.com/eu/en/home/11-item-item.html.
I want to add this ?SubmitCurrency=anything&id_currency=1 in last of that url.
But just only for one time adding this and not showing users is this possible?
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(eu/en/home/11-item-item\.html)$ $1?SubmitCurrency=anything&id_currency=1 [L]
I have been unable to get a redirect to work. The behavior I was hoping to have would redirect from:
www.mysite.com/?id=12345
to
www.mysite.com/?other_id=12345
The rule I wrote seems to grab any url matching the very end like:
www.mysite.com/directory/another/?id=12345
I just want this to work at the root level, not all levels.
The rule I currently have is as follows:
RewriteCond %{QUERY_STRING} ^(.*&)?id=([^&]+)$
RewriteRule ^(.*)$ http://%{SERVER_NAME}/?other_id=%2 [R=301,L]
For some reason I had to include the first regex as it was not accepting it without it. Without the first ^(.*&) It kept saying that the site was creating a redirect that would not work and bombing out, which may be a part of my problem.
IS there a better way to write this rule? or is a root level match alone not possible?
Thank you,
Silvertiger
Change your regex from ^(.*)$ to `^$``:
RewriteCond %{QUERY_STRING} ^(.*&)?id=([^&]+)$
RewriteRule ^$ http://%{SERVER_NAME}/?other_id=%2 [R=301,L]
The ^(.*)$ regex matches any request URI, so /, and /foo and /dir1/dir2/dir3/file.txt will all match. But the ^$ only matches /.
I'm trying to 301 redirect a paginated blog list from an old site onto a new url.
I think I'm getting pretty close with the RewriteRule but I'm not quite there yet, this is what I have:
RewriteCond %{QUERY_STRING} ^page=
RewriteRule ^(blog)?$ http://www.newdomain.com/news/page/$1? [R=301,L]
Using this rule if I go to
http://www.olddomain.com/blog?page=1
I currently get redirected to
http://www.newdomain.com/news/page/blog
I would like to be sent to
http://www.newdomain.com/news/page/1
I'm sure its just something small and simple that I'm missing.
Edit
Expanding on the solution below, I've added tags/category support to the rewrite rule using $1.
RewriteCond %{QUERY_STRING} ^page=([^&]+) [NC]
RewriteRule ^blog/tag/([^/\.]+)?$ http://www.newdomain.com/news/tag/$1/page/%1? [R=301,L,NC]
Few minor mistakes in your code.
You need to capture page parameter's value from query string first
Then use that capture value using % instead of $1
No need to capture blog since you don't need it.
Change your code with:
RewriteCond %{QUERY_STRING} ^page=([^&]+) [NC]
RewriteRule ^blog/?$ http://www.newdomain.com/news/page/%1? [R=301,L,NC]