?
Solved

Replace space in file name - htaccess

Posted on 2011-02-25
7
Medium Priority
?
957 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 500 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

850 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