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

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]

Related

Redirect rule to change url parameters with slashes / in .htaccess file

I need to change url parameters with slashes.
My current working url is
https://www.example.com/Blog-Details.php?blog=test-title
I need to change it like below
https://www.example.com/Blog-Details.php/blog/test-title
My htaccess file is
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#RewriteRule ^([a-z_]+).html $1.php
RewriteRule ^([A-Za-z_-]+).html $1.php
RewriteRule ^([a-z]+)/([a-z]+)/(.*)\.html /market_material.php?ind=$3
#RewriteRule ^([A-Z]{2})/([\+a-z\ ]+)\.html$ /reports_content.php?
report_id=$1
#RewriteRule ^report/([0-9]+) /reports_content.php?report_id=$1
RewriteRule ^([0-9]+)/(.*)\.html /reports_content.php?report_id=$1
#RewriteRule ^blog/([0-9]+) /Blog-Details.php?blog=$1
#RewriteRule ^Blog-Details.html/([^/]+)?$ $1.php?blog=$2 [L]
RewriteRule ^([^.]+?)/?$ /Blog-Details.html?p=$1 [NC,L]
</IfModule>
I added this line to convert parameters with slashes
RewriteRule ^([^.]+?)/?$ /Blog-Details.html?p=$1 [NC,L]
Try using the following RewriteRule in your .htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} blog=(.+) [NC]
RewriteRule ^(.*)$ http://www.example.com/Blog-Details.php/%1? [R=301, NC, L]
This is grabbing your variable blog= using a condition and then adding it onto the end of your URL using %1. You'll notice I've also added a ? onto the end of the RewriteRule, this is to stop the original query string from appearing on the end of the URL.
The rewrite works by using 301 redirection, you might want to change this to 302 to make it a temporary redirect while testing.
Make sure you clear your cache before testing this.

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]

How to replace the first parameter name in query string using .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]

Rewrite rule htaccess disturbing other rewrite rules

I have a page on my website that is getting generated dynamically to list all outlets based on cityf parameter and below is rewrite rule to convert it into SEO friendly URL and it is working pretty well.
RewriteRule ^([^/.]+)/?$ /cityres?cityf=$1 [L]
I have a blog page on my website and .htaccess is as below to convert SEO Friendly URL (http://example.com/title-of-blog)
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]
Now the problem here i am facing that when someone visits blog page then the link http://example.com/title-of-blog instead of displaying blog detail on the page, displays my Error message that No outlets near title-of-blog.
I got the issue that Apache is not able to identify when to rewrite cityres page and when to rewrite blogdetail page.
Someone suggested that Make sure that each rule has a common prefix (e.g. /blog/page1 and /news/page2). but i did not get that.
Any suggestions here please?
EDIT:
Whole htaccess is as below
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index
RewriteRule ^index\.php$ / [L,R=301]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
# remove .php from URL
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
# remove .html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)\.html$ /$1 [L,R=301]
ErrorDocument 404 /error-page
ErrorDocument 403 /error-page
RewriteRule ^food-([^-]*)-([^-]*)\.html$ /pdetail?res_id=$1&location=$2 [L]
RewriteRule ^foodies-([^-]*)-([^-]*)$ /pdetail_new?res_id=$1&location=$2 [L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ /pdetail_ne?location=$1&res_id=$2&name=$3 [L]
RewriteRule ^blog/([^/.]+)/?$ /blogdetail_fm?prmn=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !cityres
RewriteRule ^([^/.]+)/?$ /cityres?cityf=$1 [L]
Both your rules match the exact same pattern. Therefore, the first rule will always match and the second rule does nothing.
Looking at the first rule:
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]
This matches http://example.com/title-of-blog as well as http://example.com/city-name
When you look at it, you can tell which needs to be handled by blogdetail and which needs to be handled by cityres, but the regex ([^/.]+) sees them both as exactly the same, and matches both. Your regex doesn't know the difference, so whatever the first rule is, both URL's will get matched by it.
Like you said, someone suggested using a prefix. That way, the regex knows which is which:
RewriteRule ^city/([^/.]+)/?$ /cityres?cityf=$1 [L]
RewriteRule ^blog/([^/.]+)/?$ /blogdetail?prmn=$1 [L]
ANd your URLs will look like:
http://example.com/city/city-name
http://example.com/blog/title-of-blog
If you're really hung up about not adding prefixes, you can remove the second prefix:
RewriteRule ^city/([^/.]+)/?$ /cityres?cityf=$1 [L]
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]
So that you have:
http://example.com/city/city-name
http://example.com/title-of-blog
EDIT:
Your 500 server error is caused by the rules looping. You need to add a condition so that they won't keep matching:
RewriteRule ^blog/([^/.]+)/?$ /blogdetail?prmn=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !cityres
RewriteRule ^([^/.]+)/?$ /cityres?cityf=$1 [L]

Rewrite static html to dynamic php error bad flag delimiters

Having gone through some suggestions about rewriting static url to php url i have hit snag trying to redirect http://www.example.com/clothing to http://www.example.com/index.php?main_page=index&cPath=999
using this rule
RewriteRule ^clothing/index.html index.php?main_page=index&cPath=999 [L]
I keep getting
rewriterule: bad flag delimiter
even after changing/adding / and \ to the rule.
This is my .htaccess file
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# From Ultimate SEO URLs
RewriteRule ^(.*)-p-(.*).html$ index\.php?main_page=product_info&products_id=&% {QUERY_STRING} [L]
RewriteRule ^(.*)-c-(.*).html$ index\.php?main_page=index&cPath=&%{QUERY_STRING} [L]
RewriteRule ^(.*)-m-([0-9]+).html$ index\.php?main_page=index&manufacturers_id=&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pi-([0-9]+).html$ index\.php?main_page=popup_image&pID=&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pr-([0-9]+).html$ index\.php?main_page=product_reviews& products_id=&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pri-([0-9]+).html$ index\.php?main_page=product_reviews_info&products_id=&%{QUERY_STRING} [L]
RewriteRule ^(.*)-ezp-([0-9]+).html$ index\.php?main_page=page&id=&%{QUERY_STRING} [L]
# All other pages
# Don't rewrite real files or directories
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*).html$ index\.php?main_page=&%{QUERY_STRING} [L]

Resources