473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

mod_rewrite, replace spaces (%20) in URL param value with dash "-"

30
Hi,

I'm struggling to find an answer to my problem. In order to make my dynamic URLs search engine friendly, I need to replace spaces (%20) that appear in the URL with a dash "-".

For example,
change this dynamic URL:
www.example.com/directory.php?name=very%20nice%20house

to simply: www.example.com/very-nice-house

Really need some help with the complete mod_rewrite code.

Cheers.
Jan 23 '09 #1
1 11907
Atli
5,058 Expert 4TB
Hi.

You should go through the mod_rewrite documentation. There are also some very nice tutorials available through Google.

Some regular expression knowledge is also needed to work with mod_rewrite. I recommend finding a nice tutorial on that as well.

To start you off, let me offer this:
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^(.*?)$ directory.php?name=$1
Which will simply take everything in the path of your URL (the part after the .com) and pass it as the "name" GET parameter to a "directory.php" file.

If you need to change dashes in to spaces, you should let PHP handle that. (Much easier than having mod_rewrite do it)
Jan 29 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Miguel J. Jiménez | last post by:
Hi, I have the following node: <node> Some text here with lots of inside it... </node> and I would like it to transfrom it using XSLT to the following: Some text<br/> here with</br> lots...
5
by: K.Simon | last post by:
Hello, it's very often neccessary to replace strings or a single character in my stylesheets. My solution looks awful and very long. Now i thought to solve this with an array like structure but...
4
by: Randell D. | last post by:
Folks, Can someone help my syntax? var z=myForm.myInputTag.value.string().replace(" ","-"); I would expect the above to allow z to take the value of an input tag (called myInputTag) and...
8
by: Peter van Schie | last post by:
Hi all, Give an xml document that looks something like this: <?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet type="text/xsl"...
2
by: JS | last post by:
Is it possible to do multiple replaces in a string? Example: I'm trying to replace all of the spaces with "%20" and "#" with "%23", etc. I also need to replace the "?", "!", " ' ", etc. I know...
1
by: Random Task | last post by:
Can someone help me by providing an example of how to replace / with \ in a string in xslt2. The characters / and \ seem to cause me grief ... I am trying the below code currently ... Any...
2
by: David | last post by:
Sent this to alt.php a couple of days back, but doesn't look like I'll get an answer, so trying here. I'm trying to convert a script to use friendly URLs, I've done this before, but my PHP...
3
by: FunkHouse9 | last post by:
I'm working on a form to collect data in a textarea which and am trying to keep returns and spaces. I have a couple of functions that I Frankensteined together to replace returns with <br> and to...
3
by: Hvid Hat | last post by:
Hi I want to highlight (make it bold) a word in some text I'm getting in XML format. My plan was to replace the word with a bold (or span) tag with the word within the tag. I've found the code...
6
by: Rauan Maemirov | last post by:
Hi, all. I'm trying to replace <object ...><embed... /></objectwith <imgtag and vice-verse. It's like implementation of media plugin of Tiny MCE editor. I tried to watch their code, but it's too...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.