Solved

Replace space in file name - htaccess

Posted on 2011-02-25
7
949 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 

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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

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…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 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