1

Please take it easy on me, but I'm still new in htaccess rewrites and all, never done it before.

I'm trying to replace %20 with - in my urls. I can't seem to figure out.

Could you tell me whats wrong in the following htaccess code? Only in the URL Rewrite part

# Begin hotlink protection # RewriteEngine on RewriteCond %{HTTP_REFERER} !^http://webawwards.com/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://www.webawwards.com/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://webawwardscom.ipage.com/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://www.webawwardscom.ipage.com/.*$ [NC] RewriteRule .(gif|jpg|png)$ - [F] # End hotlink protection # # Begin cache control # ExpiresActive on ExpiresDefault "now plus 240 minutes" ExpiresByType text/html "now plus 240 minutes" <FilesMatch "\.(css|png|bmp|ico|htm|gff|html|js|jpg|jpeg|gif|gcf)$"> FileETag MTime Size ExpiresDefault "now plus 240 minutes" </FilesMatch> # End cache control # # Url rewritting start # RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] RewriteCond %{HTTP_HOST} ^webawwards\.com [NC] RewriteRule (.*) http://www.webawwards.com/$1 [L,R=301] # remove spaces from start or after / RewriteRule ^(.*/|)[\s%20]+(.+)$ $1$2 [L] # remove spaces from end or before / RewriteRule ^(.+?)[\s%20]+(/.*|)$ $1$2 [L] # replace spaces by - in between RewriteRule ^([^\s%20]*)(?:\s|%20)+(.*)$ $1-$2 [L,R] # Url rewrite end # # Enable gzip compression <ifModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </ifModule> 

It doesnt seem to work.

I want www.domain.com/blog/post.php?title=text%headline to be replaced by www.domain.com/blog/title-headline

I know the code above is wrong but I cant figure out where

3
  • possible duplicate of .htaccess redirect all urls using %20 to - Commented Apr 12, 2014 at 20:39
  • I tried that already. Didn't work for me. Commented Apr 12, 2014 at 20:50
  • "text%headline" - maybe "text%20headline"? Commented Apr 12, 2014 at 21:16

1 Answer 1

1

Try this instead

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /blog/post\.php\?title=(.*)%20(.*)\ HTTP RewriteRule ^ /blog/%2-%3? [R=301,L] 

So if the title contains a space, it will be rewritten to a -

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.