Reputation: 1544
Hello everyone i am new in .htaccess
URL rewriting, i have URL as like
but i want it as like this
thanks in advance...
my
.htaccess
code
#Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
# executes repeatedly as long as there are more than 1 spaces in URI
RewriteRule "^(\S*)\s+(\S*\s.*)$" /$1-$2 [L,NE]
# executes when there is exactly 1 space in URI
RewriteRule "^(\S*)\s(\S*)$" /$1-$2 [L,R=302,NE]
#RewriteBase /
## don't touch /forum URIs
RewriteRule ^forums/ - [L,NC]
## hide .php extension snippet
# To externally redirect /dir/foo.php?name=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?name=([^&\s]+) [NC]
RewriteRule ^ %1/%2? [R,L]
# To internally forward /dir/foo/12 to /dir/foo.php?name=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)?$ $1.php?name=$2 [L,QSA
Upvotes: 0
Views: 57
Reputation: 784878
Change your first 2 rules to this so that you can convert both +
and space to hyphens:
# executes repeatedly as long as there are more than 1 spaces in URI
RewriteRule "^([^\s+]*)[\s+]+([^\s+]*[\s+].*)$" /$1-$2 [L,NE]
# executes when there is exactly 1 space in URI
RewriteRule "^([^\s+]*)[\s+]+([^\s+]*)$" /$1-$2 [L,R=302,NE]
Upvotes: 1