Remove last part of dynamic URL with htaccess - .htaccess

Can any one please help with this :
i am trying to redirect this :
https://www.example.com/site/members/user-id/page/page-id/?user_filter=points
to this
https://www.example.com/site/members/user-id/
please note that /user-id/ & /page-d/ are numbers that changes in every link.
I tried searching online and tried to come up with some thing but yet no success
Here what i tried so far
RewriteRule ^site/members/[0-9]{4}/page/$ https://www.example.com/site/members/[0-9]{4}/? [R=301,NE,NC,L]
and this approach:
RewriteCond %{REQUEST_URI} ^site/members/([0-9]{4}+)$/pages/ [NC,OR]
RewriteRule (.*) /site/members/1$ [L,R=301]
Would Appreciate Any Help On that
Thanks

You can use the following rule:
RewriteCond %{REQUEST_URI} ^/site/members/([0-9]+)/pages/ [NC]
RewriteRule (.*) /site/members/%1? [L,R=301]
Make sure to clear your browser cache before testing this.

Related

Htaccess shows both: short url and long at the same time

everyone!
I need help, because, I don't understand how's it can be.
I have easy htaccess:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?cat=$1
RewriteCond %{HTTPS} =off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]
When I open any page, i have to see smth like this:
site.com/games
but I see:
site.com/games?cat=games.
What can it be and how can I resolve this? Very sorry, if this question was already resolved here, but I couldn't find it.
Swap the order of your rules:
RewriteEngine on
RewriteCond %{HTTPS} =off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?cat=$1
I also tweaked your rules a little, removing unnecessary QSA flag and unused capturing. Also specifying an external redirect for the first one.
Let me know any problems.

Multipule Query Strings .htaccess Redirect

Im a bit stuck where I need to redirect 80+ URLs' which have
content.php?111-rest-of-url
RewriteCond %{QUERY_STRING} ^?64-random-url-here-again$
RewriteRule ^content.php$ https://www.newdomain.com/random-url-here-again/? [R=301,L,QSD]
RewriteCond %{QUERY_STRING} ^?61-random-url-here$
RewriteRule ^content.php$ https://www.newdomain.com/random-url-here/? [R=301,L,QSD]
And there are around another 80 url's written out like this. However, when testing on site, no matter what URL you try...it always returns the first one in the .htaccess
From what I have been reading am I correct in assuming you can only use one query string of this kind ? if so is there away around this ?
Thanks in advance.
Ok so I managed to accomplish what I need by doing the following, hopefully it will help someone else.
RewriteCond %{REQUEST_URI} ^/content\.php$
RewriteCond %{QUERY_STRING} ^196-random-url-here-again$
RewriteRule ^(.*)$ https://www.newdomain.com/random-url-here-again/? [R=301,L,QSD]
RewriteCond %{REQUEST_URI} ^/content\.php$
RewriteCond %{QUERY_STRING} ^196-random-url-here$
RewriteRule ^(.*)$ https://www.newdomain.com/random-url-here/? [R=301,L,QSD]
Not sure what the difference is but it works :), would be grateful to hear from someone to explain the difference in what I have done so I understand it in the future.

htaccess redirect to certain page depending on condition

I have the following urls:
www.mydomain.com/contacto.html
www.mydomain.com/pedidos.html
www.mydomain.com/quienes.html
I want to redirect them to:
www.mydomain.com/
I have wrote the following script, but it is not working ok.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(contacto\.html|pedidos\.html|quienes\.html)$
RewriteRule ^ / [R=301,L]
Do you have any idea how to make this thing working?
Thanks in advance,
Emanuel
This is not the first time I see the problem here. I do not know why.
But I know it works like that:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(contacto\.html|pedidos\.html|quienes\.html)$
RewriteRule ^ http://www.domain.com/ [R=301,L]
Delete your cache or try from other browser if it does not work the first time.
Thanks Croises,
I've used something very similar to what you has suggested.
I did the following:
RewriteCond %{REQUEST_URI} ^/(home|pedidos|quienes|contacto).html$
RewriteRule .* / [R=301,L]
Thank you very much for your help.
BR

htaccess RewriteRule for unknown folder name not working

I have been working on this for a few days and had to face the facts...I'm stuck! I have a very simple RewriteRule that works well:
RewriteRule ^(.*)testfolder/(.*).php(.*)$ $1newfolder/subfolder/$2.php$3 [L]
This changes urls from something like:
http://mydomain.com/testfolder/phpfile.php#/login
to
http://mydomain.com/newfolder/subfolder/phpfile.php#/login
The problem is that I need to create a rule that will allow "testfolder" to have a dynamic name. (I have 50+ rules doing this for different folders and I need one rule that catches all of them.)
With no success, I have been trying to use the following to reproduce the results above:
RewriteCond %{REQUEST_URI} ^/[a-z]*/(.*).php(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^/newfolder/subfolder/$1.php$2$
RewriteRule ^[a-z]*/(.*).php(.*)$ newfolder/subfolder/$1.php$2 [QSA,NC,L]
I need to resolve this quickly so any ideas? assistance? or help would be greatly appreciated. Thanks in advance!
Try this rule:
RewriteCond %{REQUEST_URI} !^/newfolder/subfolder/ [NC]
RewriteRule ^[^/]+/([^.]+)\.php(.*)$ /newfolder/subfolder/$1.php$2 [NC,L]

how to redirect from modules.php?name=News&file=article&sid=XXX to domain.eu/XXX?

I would like to redirect all url requests with the phpnuke string modules.php?name=News&file=article&sid=XXX (xxx is a number) to my domain-name.eu/XXX . How is that possible?
i tried
RewriteCond %{QUERY_STRING} ^(.*&|)modules.php?name=News&file=article&sid=(&.*|)$
RewriteRule ^(.*)$ %1domain.eu/%2 [L,R=301]
but it has no effect. Where is the mistake?
Also i don't understand why a simple
RewriteRule ^(.*)$ /modules.php?name=News&file=article&sid=$1 [L,R=301]
doenst work. Any ideas?
Thanks a lot for any help.
Not sure why I'm seeing this in Drupal questions. But try this.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/modules\.php$
RewriteCond %{QUERY_STRING} ^sid=([0-9]*)$
RewriteRule ^(.*)$ http://domain.eu/%1 [R=301,L]
You can't match everything after the sid=(.*) regex part in the URL in most cases. modules.php?name=News&file=article&sid=XXX and modules.php?sid=XXX&name=News&file=article are the same in functionality.
Learned at http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/

Resources