Reputation: 312
I have two links for a place.
link 1: http://www.myhappyjourney.com/Rae%20Bareli link 2: http://www.myhappyjourney.com/Rae-Bareli
I want to redirect link 1 to link 2 permanently. All urls with space to with hyphen.
Tried the following code. But not working. It is putting index.php in the url.
RewriteCond %{THE_REQUEST} (\s|%20)
RewriteRule ^([^\s%20]+)(?:\s|%20)+([^\s%20]+)((?:\s|%20)+.*)$ $1-$2$3 [N,DPI]
RewriteRule ^([^\s%20]+)(?:\s|%20)+(.*)$ /$1-$2 [L,R=301,DPI]
Note: Project is in codeigniter.
Full .htaccess code
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteCond %{HTTP_HOST} !^(.*)\.myhappyjourney\.com$ [NC]
RewriteRule ^(.*)$ http://www.myhappyjourney.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} (\s|%20)
RewriteRule ^([^\s%20]+)(?:\s|%20)+([^\s%20]+)((?:\s|%20)+.*)$ $1-$2$3 [N,DPI]
RewriteRule ^([^\s%20]+)(?:\s|%20)+(.*)$ /$1-$2 [L,R=301,DPI]
Upvotes: 2
Views: 161
Reputation: 785196
You can use this rule for space to hyphen redirect:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule "^(\S*)\s+(\S*\s.*)$" $1-$2 [N]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule "^(\S*)\s(\S*)$" /$1-$2 [L,R=301]
RewriteCond %{HTTP_HOST} !^(.*)\.myhappyjourney\.com$ [NC]
RewriteRule ^(.*)$ http://www.myhappyjourney.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Upvotes: 2