How to replace the first parameter name in query string using .htaccess? - .htaccess

I need to change the name of the first parameter in the query string from p (lower case) to P (upper case). It is the first parameter in the query string.
For example, I need to change the url from:
http://www.example.com/shop/?p=product_name
to
http://www.example.com/shop/?P=product_name
The framework is wordpress.
The .htaccess code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^p=([^&])$
RewriteRule ^securestore/?$ $0?P=%1 [L,NC,R=302]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RedirectMatch 301 ^(.*)/EcoSupp$ $1
</IfModule>

You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^p=([^&]+)
RewriteRule ^securestore/?$ $0?P=%1 [L,NC,R=301]

Related

Redirect URL if specific parameter doesn't exist

I have this example URL
www.something.com/order?_vacation=bahamas
The Value "Bahamas" can vary of course based on the location
I would like to redirect this URL
www.something.com/order
If anyone was typing it in the address bar without the parameter _vacation and it's value
Let's say - Redirect him to the homepage
www.something.com
Can anyone suggest how to do it using htaccess?
Thanks
Update here is my htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} !(?:^|&)_vacation=[^&]+ [NC]
RewriteRule ^order/?$ /? [L,NC,R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /tripwith/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /tripwith/index.php [L]
</IfModule>
# END WordPress
You may use this rule as your topmost rule for this purpose:
RewriteEngine On
RewriteCond %{QUERY_STRING} !(?:^|&)_vacation=[^&]+ [NC]
RewriteRule ^order/?$ /? [L,NC,R=301]

.htaccess: rewrite to new URL structure

I'm trying to have the following URL redirect to a new structure:
Before: http://example.com/profile/?name=some-one
After: http://example.com/profile/some-one/
The some-name will change depending on the user's account, so I want that part to be dynamic. This is what I have for my .htaccess
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{QUERY_STRING} (^|&)name=(.*)
RewriteRule ^profile/$ /profile/$1/? [L,R=301]
According to this online htaccess tester, this would be the result:
http://example.com/profile//
Any help on clarifying why it's not carrying over the dynamic some-name? If it matters, this is for a WordPress site which already has the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Try
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{QUERY_STRING} (^|&)name=(.*)
RewriteRule ^(.*)$ /profile/%2/? [R=301,L]
Use % for vars captured in RewriteCond's

URL rewrite for part of domain name

I feel this should be an easy fix but I'm struggling to get it done right.
I have the URL:
http://www.testing.com/toursgbr/my-post
http://www.testing.com/toursgbr/my-post-2
I need to rewrite the URL to:
http://www.testing.com/tours/gbr/my-post
http://www.testing.com/tours/gbr/my-post-2
I got as far as the following:
RewriteRule ^toursgbr/(.*) /tours\/gbr/$1 [L]
This is what's currently in the htaccess file:
RewriteEngine on
ErrorDocument 404 http://www.ausweb.com.au/web-hosting
AddHandler server-parsed html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^seabreezepark\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.seabreezepark\.com\.au$
RewriteRule ^/?$ "http\:\/\/theseabreezepark\.com\.au\/" [R=301,L]
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]
and got nowhere pretty fast. I just want to look for the word "toursgbr" and change it to "tours/gbr" in summary.
Put the Following code at root .htaccess file :
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} !\s/+tours/gbr/ [NC]
# the above line will exclude any request having tours/gbr/ from the follwoing rule.
RewriteRule ^toursgbr/(.*)$ tours/gbr/$1 [R=302,L,NE]
# the above line will change any requested url having toursgbr/ to be tours/gbr/ temporary
# and you can change it to permanent by changing [R=302,L,NE] to [R=301,L,NE]
# but check the code as it is first then change it
RewriteRule ^tours/gbr/(.*)$ toursgbr/$1 [L,NC]
# the above line will internally map any request having tours/gbr/ to its original path
Try :
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]
Do not use the full url in rewrite target if you want to internally redirect /toursgbr/foo to /tours/gbr/foo without changing the url in browser.
Your corrected htaccess :
ErrorDocument 404 http://www.ausweb.com.au/web-hosting
AddHandler server-parsed html
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?seabreezepark\.com\.au$
RewriteRule ^/?$ http://theseabreezepark.com.au/ [L,R=301]
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

htaccess rewrite %3F and %3D to ? and =

I'm wanna rewrite all incoming URLs who at end have %3Ffull%3D1 to ?full=1
I'm try this in htaccess but not work:
RewriteRule ^(.*)%3F(.+)%3D(.+)$ $1?$2=$3 [R=301]
here is full .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)%3F(.+)%3D(.+)$ $1?$2=$3 [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I recently implemented the following .htaccess code to accomplish this - I've modified it to fit your scenario of using the "full" parameter.
# replace %3F with ? and %3D with =
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\%]+)\%3[Ff]full\%3[dD]([^\ ]+)\ HTTP/
RewriteRule \.*$ http://www.mywebsite.com/%1?full=%2 [R=301,L]
Try adding the L flag in the rule that handles the query string:
RewriteRule ^(.*)%3F(.+)%3D(.+)$ $1?$2=$3 [L,R=301]
otherwise, the rewritten URI could end up getting handled by the last rule (RewriteRule . /index.php [L]) and yet still get redirected because the URI was flagged for a 301. Also, if the original URL that you are trying to redirect contains %3Ffull%3D1 in the query string itself, then your rule isn't going to match that, you'd need something like:
RewriteCond %{QUERY_STRING} ^(.*)%3Ffull%3D1(.*)$
RewriteRule ^(.*)$ $1?%1&full=%2 [L,R=301]

replace word through htaccess

I have a wordpress site. Here is link to site. I want to redirect www.abc.com/?portfolios=letters to www.abc.com/?files=letters.
I tried editing in code, but din't worked.
Here is htaccess
Options +FollowSymLinks
RewriteEngine on
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^womackpi.com/?portfolio=(.+) womackpi.com/?files=$1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
This should do:
RewriteRule ^abc.com/?portfolios=(.+) abc.com/?files=$1 [NC]
It works for me!
You will also need:
Options +FollowSymLinks
RewriteEngine on
Above the previous statement.
Query strings are not part of the URI that is used to match against the expression in RewriteRule..
Try replacing RewriteRule ^womackpi.com/?portfolio=(.+) womackpi.com/?files=$1 [NC] with:
RewriteCond %{HTTP_HOST} ^(www\.)?womackpi.com$ [NC]
RewriteCond %{QUERY_STRING} (^|&)portfolio=(.+)(&|$) [NC]
RewriteRule ^(.*)$ /$1?files=%2 [L]
Add an R inside the [L] brackets if you want to redirect the browser (changing the URL in the address bar).

Resources