remove comma (%2C), apostrophe (%27), colon (%3A) from url - .htaccess

How to remove comma (%2C), apostrophe (%27), colon (%3A) from title of the url using htaccess
my url is
https://xklsv.me/Funding-Friday%3A-Jelly2/fred/August-7th-2020
desired url
https://xklsv.me/Funding-Friday:-Jelly2/fred/August-7th-2020
https://xklsv.me/Tactics%2C-Political-Tactics/BigRedCar/August-9th-2020
desired url
https://xklsv.me/Tactics,-Political-Tactics/BigRedCar/August-9th-2020
this is my code what i have tried
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^title=([^/]+)/([^/]+)/([^/]+)/(.+)$
RewriteRule ^viewblog1\.php$ /%1/%2/%4? [R=301]
RewriteRule ^viewblog1/([\w+%]{2,50})$ /viewblog1.php?q=$1 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ viewblog1.php?title=$1&user=$2&date=$3
RewriteRule ^([^/]+)/([^/]+)/(.+)$ viewblog1.php?title=$1/$2/$1/$3 [L]
RewriteRule ^(.*):(.*)$ /viewblog1.php?title=$1/$2/$1/$3 [L]
RewriteRule ^(.*),(.*)$ /viewblog1.php?title=$1/$2/$1/$3 [L]

You may use these 3 redirect rules at top of your .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(\S*?)%3A(\S*)
RewriteRule . /%1:%2 [L,NE,R=301]
RewriteCond %{THE_REQUEST} \s/+(\S*?)%2C(\S*)
RewriteRule . /%1,%2 [L,NE,R=301]
RewriteCond %{THE_REQUEST} \s/+(\S*?)%27(\S*)
RewriteRule . /%1'%2 [L,NE,R=301]

Related

htaccess rule issue in redirecting the url

I want to redirect all below pattern url to before "?" url
i.e
Xyz.com/worksheet/rebus/?random=testing11
Xyz.com/worksheet/rebus/?abc
Xyz.com/worksheet/rebus/?l=1
should be redirected to
Xyz.com/worksheet/rebus/
I tried many things but not able to succeed. How can i do using .htaccess
Rules tried
RewriteBase /worksheet/
RewriteRule ^rebus/?$ /worksheet/rebus/ [L,R=301]
Overall
RewriteEngine On
RewriteBase /worksheet/
RewriteCond %{THE_REQUEST} \s/(rebus)/\?(\S+)\s [NC]
RewriteRule ^ /worksheet/%1/ [R=301,L]
#RewriteRule ^rebus/?$ /worksheet/rebus [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)?$ index.php?url=$2&tableName=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)?$ index.php?url=$2&tableName=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)?$ index.php?url=$2&tableName=$1&showSol=$3 [L,QSA]
Have it this way:
RewriteEngine On
RewriteBase /worksheet/
# \?\S matches at least one character after ?
RewriteCond %{THE_REQUEST} \s/(worksheet/rebus)/\?\S [NC]
RewriteRule ^ /%1/? [R=301,L]
RewriteRule ^rebus/?$ /worksheet/rebus? [L,R=301,NC]
# skip all rules for real files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?url=$2&tableName=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?url=$2&tableName=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?url=$2&tableName=$1&showSol=$3 [L,QSA]

Rewrite URL with .htaccess and exclude files

i have this piece of code in .htaccess file to rewrite URLS from upper case to lower case :
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
My question is, how can i exclude files like .js, .css, and more from this rule?
My htaccess have other rules too:
RewriteEngine on
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
Thank you.
You can add another negative RewriteCond:
RewriteCond %{THE_REQUEST} !\.(css|js|gif|jpe?g|ico|tiff)\s [NC]
RewriteCond %{THE_REQUEST} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
This will redirect all requests except if it ends with those extensions.

Htaccess same rule for 2 files not working

I am trying to create friendly pagination using htaccess file.
But its not working I guess I am using wrong rule for files.
Check out my codes below.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+search\.php\?q=([^\s&]+) [NC]
RewriteRule ^ /search/%1/? [R=301,L]
RewriteRule ^search/$ search/%1 [L,R=301,NC]
RewriteRule ^search/(.*)/$ search.php?q=$1 [L,NC]
RewriteRule ^new/(.*)$ new.php?page=$1 [L,NC]
RewriteRule ^(.*)/$ cat.php?id=$1 [NC]
RewriteRule ^(.*)/(.*)/$ cat2.php?id=$1&page=$2 [NC,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ post.php?id=$1 [NC]
Everything is working fine, only cat2.php is not working.
How to fix it?
You need to switch the order around between your 2 cat rules. (.*) matches everything, including slashes, so it will always match whatever cat2 matches. Try just swapping their orders and include L flags:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+search\.php\?q=([^\s&]+) [NC]
RewriteRule ^ /search/%1/? [R=301,L]
RewriteRule ^search/$ search/%1 [L,R=301,NC]
RewriteRule ^search/(.*)/$ search.php?q=$1 [L,NC]
RewriteRule ^new/(.*)$ new.php?page=$1 [L,NC]
RewriteRule ^(.*)/(.*)/$ cat2.php?id=$1&page=$2 [L,NC,QSA]
RewriteRule ^(.*)/$ cat.php?id=$1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ post.php?id=$1 [NC]

.htaccess RewriteRule url to new

Bonjour,
I try to redirect urls of a website
Example :
www.exemple.net/?p=2
to
www.exemple.net/index-2.html
www.exemple.net/?p=35
to
www.exemple.net/index-35.html
etc...
So i add this lines to my .htacess :
RewriteCond %{QUERY_STRING} ^(?)p=(.*)$ [NC]
RewriteRule .* /index-%1.html [L,R=301]
But i'm redirected to http://www.exemple.net/index-2.html?p=2
My .htaccess :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^exemple.net$
RewriteRule ^(.*) http://www.exemple.net/$1 [QSA,L,R=301]
RewriteCond %{QUERY_STRING} ^(?)p=(.*)$ [NC]
RewriteRule .* /index-%1.html [L,R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Can you help me please ?
You need to add a question mark at the end of the destination to discard the query string:
RewriteRule .* /index-%1.html? [L,R=301]
Alternatively, use the QSD flag:
RewriteRule .* /index-%1.html [QSD,L,R=301]
Try :
#Redirecting /?p=2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/\?p=([^&\s]+) [NC]
RewriteRule ^ /index-%1.html? [NE,NC,R,L]
#Redirecting /transfer?p=2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/transfer\?p=([^&\s]+) [NC]
RewriteRule ^ /transfer-%1.html? [NE,NC,R,L]
#Redirecting /blog?p=2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/blog\?p=([^&\s]+) [NC]
RewriteRule ^ /blog-%1.html? [NE,NC,R,L]

Remove %2F from URLs with mod_rewrite

I would like to remove the '%252F' from my dynamically created URLs.
I have a php-file that creates links with a %2F instead of /.
The links are then represented in the URL-Bar as %252F instead of / which leads to some problems.
What I'm trying to achieve with a .htaccess-file is to redirect all %2F to / or rename all %252F to / since I can't change the php-code creating the links.
This is my .htaccess
RewriteEngine on
Options +SymlinksIfOwnerMatch
RewriteBase /
RewriteCond %{HTTP_HOST} subdomain.mydomain.com
RewriteCond %{REQUEST_URI} (.*)/style.css [OR]
RewriteCond %{REQUEST_URI} (.*)/script.js [OR]
RewriteCond %{REQUEST_URI} (.*)/logo.png
RewriteRule (.*) http://www.mydomain.com%{REQUEST_URI} [R=301,NC,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://subdomain.mydomain.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \ /([^\ \?]*)([^\ \?]*)%2f(\?.*)?\ [NC]
RewriteRule !^/ /%1/%2 [QSA]
RewriteRule ^(/.+)%2f(.*)$ $1/$2 [NC,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?dir=([^\s]+) [NC]
RewriteRule ^ %1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?dir=/$1 [L]
I can't get it to work, maybe someone else can help me with this.
Thank you very much!
The lines:
RewriteCond %{THE_REQUEST} \ /([^\ \?]*)([^\ \?]*)%2f(\?.*)?\ [NC]
RewriteRule !^/ /%1/%2 [QSA]
RewriteRule ^(/.+)%2f(.*)$ $1/$2 [NC,QSA]
Need to have the leading slash removed. URI's sent through rules in htaccess files have the leading slash stripped off:
RewriteCond %{THE_REQUEST} \ /([^\ \?]*)([^\ \?]*)%2f(\?.*)?\ [NC]
RewriteRule ^ /%1/%2 [QSA]
RewriteRule ^(.+)%2f(.*)$ $1/$2 [NC,QSA,L]
Not sure what the RewriteRule !^/ /%1/%2 [QSA] line is supposed to do, it looks like you're stripping out a trailing slash?
I managed to get rid of the first %252F in the URL and the problem of "stacking" slashes:
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://subdomain.mydomain.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?dir=%2F([^\s]+) [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?dir=([^\s]+) [NC]
RewriteRule ^ %1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?dir=/$1 [L]
I still have the problem of having %252F in my URLs though.

Resources