Single case - dynamic to static page using modrewrite in htacess - apache

I have one dynamic page:
http://blog.mysite.com/?p=25
and with htaccess and modrewrite, I want to change it to:
http://www.mysite.com/stuff/newhome.html
I know it can't be that hard but this one has me stumped, any and all help will be greatly appreciated.
EDIT
I tried:
RewriteRule ^p=25 mysite.com/stuff/newhome.html [QSA,R=301,L]
Along with variations but no success.

RewriteCond %{QUERY_STRING} ^p=25$
RewriteRule ^$ http://www.mysite.com/stuff/newhome.html [R=301]

Related

Htaccess rewrite with parameter value

I'm looking for some help. I wanted to redirect the following paramters to another url, how can I make this possible? I have googled alot of other solutions but I fail to make this one work.
https://(www).website.com/reservation#!/confirm?code=a1XapXsCmlaC0
to
https://new-website.com/test/page#!/confirm?code=a1XapXsCmlaC0
Attempted code:
RewriteRule \/reservation#!\/confirm\?code=$ https://test.com/$1
"grep"-ing the code value would make it much easier.
Any help is much appreciated.
Thanks in advance
You may use this redirect rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?website\.com$ [NC]
RewriteRule ^reservation/?$ https://test.com/test/page [L,NC,R=301]
Query string and fragment i.e. part after # will automatically be forwarded to the new URL.
Based on your shown samples, could you please try following. Where you want to redirect from (www).website.com to new-website.com in url.
Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*) [NC]
RewriteRule ^ https://new-%1/test/page#!%{REQUEST_URI} [QSA,NE,R=301,L]

Modify query string value using htacces

I want to redirect
https://www.example.com/signup?plan=basic to https://www.example.com/signup?plan=basic-monthly and https://www.example.com/signup?plan=pro to https://www.example.com/signup?plan=pro-monthly .
How can I achieve this using htaccess ?
There are many questions related to this here. But, couldn't find an answer for this specific scenario.
This is the code I tried and failed:
RewriteCond %{QUERY_STRING} (^|&)plan=pro(&|$)
RewriteRule ^signup /$0?plan=pro-monthly [R=301,L]
Also, while trying the same with "basic" instead of "pro", the word "basic" i shown in red color as if it is a keyword.
Could you please try following, written with shown samples. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{QUERY_STRING} ^(plan=(?:basic|pro))$ [NC]
RewriteRule ^(signup)/?$ $1?%1-monthly [L]
2nd solution: Or you could try following too. Make sure you either put 1st solution rules OR this one at a time.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(signup)\?(plan=(?:basic|pro))\s [NC]
RewriteRule ^ %1?%2-monthly [L]

.htaccess rewrite for category with pagination

I'm trying to write a mod-rewrite rule to handle pagination links on my site.
I'd like my URL structure to be this https://example.com/category.php?name=category-link to https://example.com/category/category-link [without pagination]
and https://example.com/category.php?name=category-link&page=2 to https://example.com/category/category-link/2 [with pagination]
I've tried the following:
RewriteRule ^category/([0-9a-zA-Z-]+)/([0-9]+) category.php?name=$1&page=$2
https://example.com/category/category-link isn't working
https://example.com/category/category-link/1 is working
2. am i able to redirect localhost/article/4/ to localhost/article/4 [here 4 is an id]
Any guidance would be much appreciated.
Could you please try following, based on your shown samples only. Please make sure you clear your browser cache after placing these rules into your htaccess file.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/category/([0-9a-zA-Z-]+)/?$ [NC]
RewriteRule ^(.*)$ category.php?name=%1 [L]
RewriteRule ^category/([0-9a-zA-Z-]+)/([0-9]+)/? category.php?name=$1&page=$2 [L]
OR you could use it without RewriteCond too. Make sure you are putting either of these NOT both of them please.
RewriteEngine ON
RewriteRule ^category/([0-9a-zA-Z-]+)/?$ category.php?name=$1 [L]
RewriteRule ^category/([0-9a-zA-Z-]+)/([0-9]+)/? category.php?name=$1&page=$2 [L]

Why is my simple rewrite code causing a redirect loop?

Would greatly appreciate it if someone could help me make this work.
I'm trying to make domain.com/painting.php?name=hello redirect to domain.com/page/hello while keeping my rewrite :
RewriteCond %{QUERY_STRING} name=([^&]+)
RewriteRule ^painting\.php$ /page/%1? [R=301,L] #redirects to page
RewriteRule ^page/([^/\.]+)/?$ painting.php?name=$1 [L] #rewrites painting
I would like to keep only the "pretty url". Please help.
Found answer here: simple 301 redirect with variable not working, why?
I'm assuming what you actually want to do is be able to accept the URL domain.com/page/hello and rewrite it (invisibly) to domain.com/painting.php?name=hello. If so, try this
RewriteRule ^page/([^/.])+/?$ painting.php?name=$1 [QSA,L]

.htaccess rewrite rule for redirects

I've been fighting this for a while and can't seem to make it work. My old system used a lot of query strings to render pages but they are no longer necessary. My url is below:
OLD URL: www.example.com/links.php?section=5&catid=52
NEW URL: www.example.com/mhfs/links
The name links is coincidental and not necessarily from the old pages name. I need to check which section and catid is present and redirect them to the appropriate page from what it is. I tried the following but this just seems to do nothing. What am I doing wrong?
RewriteCond %{REQUEST_URI} ^links.php$
RewriteCond %{QUERY_STRING} ^section=5$
RewriteCond %{QUERY_STRING} ^catid=52$
RewriteRule ^(.*)$ /mhfs/links? [R=301]
Any help would be GREATLY appreciated.
You must turn the rewrite engine on for it to work.
You probably don't want the regex start symbol on the replacement:
RewriteEngine on
RewriteCond ...
RewriteRule ...