htaccess RedirectMatch regular expression for URL? - regex

On my Wordpress blog, I used to have a plugin that I no longer need. The plugin used to create a bunch of URLs that looked like this:
http://tambnguyen.com/manage-subscriptions?srp=532&sra=s
with the postID being 532. How do I redirect the query strings so that the above URL will redirected to:
http://tambnguyen.com/?p=532
I've tried a few method without any luck (there's an optional "/" after "manage-subscriptions"
<IfModule mod_rewrite.c>
RedirectMatch 301 ^/manage-subscriptions/?\?srp=(\d{1,5})(.*)$ http://tambnguyen.com/\?p=$1
</IfModule>
Please help. Thanks!

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^srp=([^&]+) [NC]
RewriteRule ^manage-subscriptions/?$ /?p=%1 [L,R=301,NC]

Related

Redirect pages in a subfolder to a new page in same subfolder htaccess

I need to redirect several pages to a new page, the easiest way to explain is this...
http://www.example.com/numbers/0800/bronze.html TO http://www.example.com/numbers/0800/bronze-new.html
http://www.example.com/numbers/0845/bronze.html TO http://www.example.com/numbers/0800/bronze-new.html
Any ideas how to do this in one htaccess rule? Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !-new\.html$ [NC]
RewriteRule ^(numbers/.+?)\.html$ /$1-new.html [L,R,NC]

Htaccess redirect from http to https and get params

I need to redirect this:
http://www.mysite.com/pages/addtocart.php?id=XXXX
to this
https://www.mysite.com/checkout/cart/addsku?id=XXXX
Up to now, this is what I have:
RewriteRule ^/pages/addtocart.php?(.*)$ https://www.mysite.com/checkout/cart/addsku?$1 [R=301,L]
But it's not working.
Help?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^pages/addtocart\.php$ https://%{HTTP_HOST}/checkout/cart/addsku [L,R=302,NC]
PS: Query Parameter will automatically be carried over to new URL.

I need to hide directory from url using htaccess

I need to remove directories from my local website url:
Current url : http://localhost/example/trunk/frontend/www
Needed url : http://localhost/example/frontend
I need to remove trunk and www folders from url without changing files (css, js, images, ...etc) paths.
Can anyone help me please?
Thanks
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/example/trunk/[^/]*/www [NC]
RewriteRule ^(example)/([^/]+)(/.*|)$ /$1/trunk/$2/www$3 [L,NC]
UPDATE:
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /example/
RewriteRule ^((?!trunk)[^/]+)(/.*|)$ trunk/$2/www$3 [L,NC]

How to redirect to other host using mod_rewrite in Apache

I need to create Rewrite Rule for mod_rewrite in Apache but it's really hard for me to understand this whole syntax.
I have links such as:
http://www.example.com/0001/images/image1.gif
and I need them to redirect it to completely other server like:
http://127.127.127.127/0001/images/image1.gif
Is this achievable?
On example.com enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)example\.com$ [NC]
RewriteRule ^ http://127.127.127.127%{REQUEST_URI} [R=301,L]

How do I do a 301 redirect with RewriteRule using regex to change a word?

I need to rewrite my urls as follows:
http://www.mydomain.com/experiences/abc,123
http://www.mydomain.com/experience/abc,123
Basically I just need to drop the 's' in experiences. How the heck do I do this using RewriteRules with a 301 redirect?
Thanks!!!
No need for mod_rewrite. Simply use Redirect:
Redirect 301 /experiences /experience
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^experiences/(.+)$ /experience/$1 [L,R=301,NC]