Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite problem with spaces, other suggestions didn't work

         

webstar08

4:19 pm on Jun 8, 2008 (gmt 0)

10+ Year Member



Hello,
I was searching and reading a LOT,
tried many different suggestions in regards of
spaces in the URL to replace with other characters.
None of them worked so far.

Can anybody please tell me, how can I make it work?
or point me to a thread with the solution?

The problem is, I have links that look like:
[domain.com...] text with spaces
[domain.com...] few more words
[domain.com...] part that contains spaces
[domain.com...]

I need to replace spaces in such links with underscores
i.e. redirect such links with redirect 301 to:
[domain.com...]
[domain.com...]
[domain.com...]
.....

Just FYI, here is how my current .htaccess looks like:

Options +FollowSymLinks
rewriteEngine On

RewriteBase /go/
RewriteRule ^to/(.*)$ to.php/$1 [NC,R=301,L]

This allows me to use "http://domain.com/go/to/..." instead of
"http://domain.com/go/to.php/..."
That, of course, has nothing to do with what I described above.
I'm saying it here *just in case* the new rule
would somehow affect the existing one.

So, what do I need to add to my .htaccess (and where to add? at the beginning?)
in order to get apache to rewrite URLs that begin with
[domain.com...]
?

jdMorgan

4:56 pm on Jun 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> tried many different suggestions in regards of spaces in the URL to replace with other characters.

Please post your best-effort code as a basis for discussion. See our Forum Charter for more information.

Your "/to" rule is probably not what you want, since it exposes your "to.php" script URL to search engines, defeating the purpose of using mod_rewrite and "search-engine-friendly" URLs in the first place.

Given the severe search-ranking problems this can cause, I'd say that's the primary concern here, and rewriting the URLs with spaces is secondary. However, a search of this WebmasterWorld forum should turn up several previous threads here concerning rewriting URLs with spaces.

For more information about using mod_rewrite to support search-engine-friendly URLs, see this thread, "Changing Dynamic URLs to Static URLs [webmasterworld.com]" as well as the Apache section of the WebmasterWorld Library and the many previous threads posted here.

Jim

webstar08

5:17 pm on Jun 8, 2008 (gmt 0)

10+ Year Member



> Please post your best-effort code as a basis for discussion. See our Forum Charter for more information.

I tried DOZENS different thing.
Since I don't know anything about mode_rewrite I was just reading and trying things out that people recommended for similar stuff.
NOTHING worked for what I'm trying to achieve.

Well, anyway previously I was able to build that "/to/" rule and get it work.
But that "/to/" rule is just for visible links, i.e. links that users will click on. It doesn't have anything to do with my spaces problem.
I just posted it because I want to keep that rule in the .htaccess
while adding a new to replace the spaces.

Now, regarding the search engines:
This is a click tracking script/links and I don't care about search engines here.
In fact, those "/to.php/" links will only be used "invisibly" i.e. embeded in JavaScript on site for special tracking purposes.
(as opposed to "/to/" links that will be used visibly for click-tracking/redirecting purposes)

So, that click tracking script is serving two different (tracking) purposes and none of them has search engine relevance.

I'm reading the forums (here and in other places) for two days now
and was still unable to get a working solution for this (as I thought) relatively simple problem?

Andy

webstar08

5:27 pm on Jun 8, 2008 (gmt 0)

10+ Year Member



so, since what I need these links for
has nothing to do with search engines
I guess, it doesn't need to be a "301 redirect".
I just need *somehow* to rewrite/replace the spaces with underscores.

jdMorgan

9:45 pm on Jun 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you wish to replace the spaces in the links that appear on your pages, you'll have to edit the pages -- or the script that produces them, or the database from which those links are retrieved by the script, depending on how your site is set up.

mod_rewrite and/or mod_alias cannot change the links that appear on your pages. In both cases, these modules handle URLs that are requested from your server -- that is, they handle the URL *after* the link is clicked.

What mod_rewrite is good for is to redirect a user or search engine that is using an old outdated URL to a new URL, or to change the filepath used to serve content for a particular URL to a different filepath than would be used by default.

A note on your comment above: Our purpose here is to help you learn to use mod_rewrite and other Apache modules, not to write your code for you. As such, specific questions about your code are welcome. Please review our Apache Forum Charter for more information.

Jim