Solved

Replace space in file name - htaccess

Posted on 2011-02-25
7
939 Views
Last Modified: 2012-05-11
Hi,

I have urls like this on my website http://domainname.com/library/author/firstname lastname/ (some browsers show http://domainname.com/library/author/firstname%20lastname/) and I would like to always change the space in url to dash, so it become like this http://domainname.com/library/author/firstname-lastname/

How is this possible in htaccess, I assume is where I would do it.

Cheers,
0
Comment
Question by:rogaland
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:Aaron @KRONiS
Comment Utility
 First to clarify...

Are you saying that you want

http://domain.com/library/author/firstname%20lastname/   to be

http://domain.com/library/author/firstname-lastname/

if so, then if you are using WordPress (are you) you can set up the permalink structure to be different to accomplish keywords in the URL.
(.e.g. permalink settings;   /%category%/%postname%/ then in the posts, edit the slugs to be keyword-phrase)

if you are asking about how to create a mod rewrite rule to change the URLs.. (not sure what you are asking) then that's different.

Usually you just want to save the new pages with a URL slug that is firstname-lastname.

I don't know what you are using... if you have wordpress.. then you can easily do this.

if not. let me know the architecture before i start answering the wrong question please.

It sounds like you want a quick mass solution, but it may be a manual solution where you just have to change all the filenames of the pages...depending on what you are using.

hope this was a helpful start.
0
 
LVL 16

Expert Comment

by:sjklein42
Comment Utility
This .htaccess file should replace all space characters in your URL with dashes.  The [N] makes it keep going until there are no more dashes.

Options +FollowSymLinks
 
RewriteEngine On
RewriteBase /

RewriteRule ^([^\s]*)\s(.*) $1-$2 [N]

Open in new window

0
 
LVL 2

Expert Comment

by:Aaron @KRONiS
Comment Utility
thanks community!
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:rogaland
Comment Utility
Thanks for the fast reply, im a totally beginner in htaccess and I'm using Expression Engine and a tag module that produces tags with spaces and not dash between when there is two words.

@sjklein42; for the moment I need to use this code to remove the index.php from my url on expression engine:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(css=.*)$ [NC]
RewriteRule ^(.*)$ /index.php?/%1 [L]
RewriteCond $1 !^(images|admin|scripts|css|themes|favicon/.ico|robots\.txt|index.php) [NC]
RewriteRule ^(.*) /index.php?/$1 [L]

Open in new window


where should I put this code you have given me, before or after the removing the index.php code?

Thanks again for your help
0
 
LVL 16

Accepted Solution

by:
sjklein42 earned 125 total points
Comment Utility
I think this is how to combine the two .htaccess files

Options +FollowSymLinks
 
RewriteEngine On
RewriteBase /

RewriteRule ^([^\s]*)\s(.*) $1-$2 [N,L]

RewriteCond %{QUERY_STRING} ^(css=.*)$ [NC]
RewriteRule ^(.*)$ /index.php?/%1 [L]
RewriteCond $1 !^(images|admin|scripts|css|themes|favicon/.ico|robots\.txt|index.php) [NC]
RewriteRule ^(.*) /index.php?/$1 [L]

Open in new window

0
 

Author Comment

by:rogaland
Comment Utility
Absolutely brilliant!!! Thanks sjklein42
0
 

Author Closing Comment

by:rogaland
Comment Utility
Very happy!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now