htaccess rewrite " " with "-" - .htaccess

Here's my htaccess code:
RewriteEngine On
RewriteRule ^contact$ contact.php [QSA,L]
RewriteRule ^error$ error.php [QSA,L]
RewriteRule ^([^/.]+)/?$ game.php?title=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /error [L,R=301]
How can make it to work for example:
localhost/Test1%20Test2 or localhost/Test1 Test2
to work with
localhost/test1-test2

Have this rule s your very first rule:
RewriteRule "^([^ ]*) +([^ ]* .*)$" /$1-$2 [L]
RewriteRule "^([^ ]*) ([^ ]*)$" /$1-$2 [L,R=301]

Related

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

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]

.htaccess redirect with query string not working

I'm trying to do an .htaccess redirect from /modules.php?name=Farmtoschool
to a new URL.
I've looked at the other posts here but it doesn't seem to work. (full htaccess below, redirect at the bottom)
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/modules.php$
RewriteCond %{QUERY_STRING} ^name=Farmtoschool$
RewriteRule ^(.*)$ http://mynewdomain.com/modules.php?name=Farmtoschool [R=301,L]
this is the link that I want to redirect:
http://myolddomain.com/modules.php?name=Farmtoschool
Any ideas? Thanks
Reorder your rules by keeping redirect rule before WP rules:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^name=Farmtoschool$
RewriteRule ^modules\.php$ http://farmtoschoolbc.ca/modules.php?name=Farmtoschool [NC,R=301,L]
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

.htaccess - url ending char (/)

please help me with modifications .htaccess. How add ending character [/] in url.
Now .htaccess doing
www.mysite.cz/about.php > www.mysite.cz/about
www.mysite.cz/about/ > www.mysite.cz/about
i need this
www.mysite.cz/about.php > www.mysite.cz/about/
www.mysite.cz/about > www.mysite.cz/about/
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.cz$
RewriteRule (.*) http://www.mysite.cz/$1 [R=301,L]
RewriteRule ^index.php$ http://mysite.cz/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \ /+(.+)(?:/|\.php)(?:\?|\ )
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /%1 [L,R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)$ $1.php [L]
Try this :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.cz$
RewriteRule (.*) http://www.mysite.cz/$1 [R=301,L]
RewriteRule ^(index.php)$ http://mysite.cz/$1 [NC,R=301,L]
RewriteCond %{THE_REQUEST} \ /+(.+)(?:/|\.php)(?:\?|\ )
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /%1/ [NC,L,R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)/?$ $1.php [NC,L]
This adds a trailing slash at the end of the path :
www.mydomain.cz/about.php
would redirect to
www.mydomain.cz/about/

.htaccess 'IF' in rewrite rule?

This is my rule:
RewriteRule ^([^/]+)(/.+)? /negocio$2.php?shopURL=$1 [L,QSA]
If $2 doesn't exist (URL doesn't have two slashes), I want to echo '/' instead of '.php'. So the condition becomes:
RewriteRule ^([^/]+)(/.+)? /negocio/?shopURL=$1 [L,QSA]
How do I do this or archive the same result?
Pretty sure this is what RewriteCond is for!
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/([^/]+)(/.+)$
RewriteRule ^([^/]+)(/.+)? /negocio$2.php?shopURL=$1 [L,QSA]
RewriteCond %{REQUEST_URI} ^/([^/]+)$
RewriteRule ^([^/]+)(/.+)? /negocio/?shopURL=$1 [L,QSA]
Replace your code with this:
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/?$ negocio/?shopURL=$1 [L,QSA]
RewriteRule ^([^/]+)(/.+?)/?$ negocio$2.php?shopURL=$1 [L,QSA]

HTACCESS doesn't work

We are using wordpress multisite for a website.
We have some url that we need to redirect to new one.
We have tried few htaccess redirection but nothing work.
The last line is the redirection that we cannot make works.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
#redirect mobile browsers
RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
RewriteRule ^(.*)$ http://www.ourdomain.co.uk/blog [R=301,L]
RewriteCond %{HTTP_USER_AGENT} ^.*BlackBerry.*$
RewriteRule ^(.*)$ http://www.ourdomain.co.uk/blog [R=301,L]
RewriteCond %{HTTP_USER_AGENT} ^.*Palm.*$
RewriteRule ^(.*)$ http://www.ourdomain.co.uk/blog [R=301,L]
RewriteCond %{HTTP_HOST} ^ourdomain.co.uk$
RewriteRule ^(.*) http://www.ourdomain.co.uk/$1 [QSA,L,R=301]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
RewriteCond %{QUERY_STRING} page=135
RewriteRule ^index\.php$ http://www.ourdomain.co.uk/about-us/$1? [R=301,L]
Do you have any ideas?
Thanks
Try putting those last 2 lines before the first rule, so you end up with:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} page=135
RewriteRule ^index\.php$ http://www.ourdomain.co.uk/about-us/$1? [R=301,L]
RewriteRule ^index\.php$ - [L]

Resources