Solved

Replace space in file name - htaccess

Posted on 2011-02-25
7
941 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
ID: 34984947
 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
ID: 34985194
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
ID: 34985555
thanks community!
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

Author Comment

by:rogaland
ID: 34986334
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
ID: 34986740
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
ID: 34986750
Absolutely brilliant!!! Thanks sjklein42
0
 

Author Closing Comment

by:rogaland
ID: 34986751
Very happy!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Https with tomcat. A myth. 5 103
Use of SSL Certificates - http vs https 3 68
Problem with .htaccess file 4 66
Increase size of permitted URI 4 46
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

26 Experts available now in Live!

Get 1:1 Help Now