Welcome to WebmasterWorld Guest from 54.160.198.60

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

URL Rewrite - Hyphen problem

     
8:10 pm on Jan 15, 2013 (gmt 0)

Preferred Member

10+ Year Member

joined:July 13, 2005
posts: 418
votes: 0


Hi,

Hope someone can help as I'm at a loss.

Some of the URLs on my site have 2 hyphens in the first paramter:

http://www.mydomain.tld/widgets-black-white/12/


For which I have the following:


RewriteRule ([^/]+)/([^/]+)/?$ /?prod=$1&prodid=$2 [L]


Anyone know where I'm going wrong?
9:10 pm on Jan 15, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Firstly, the /?$ allows URLs with and without trailing slash to resolve. This is a duplicate content problem. The URL for a page should not end with a trailing slash.

When a URL with a trailing slash is requested, you need another rule to redirect to www and to URL without trailing slash within that single rule.

Your pattern needs a ^start anchor to be unambiguous.

Your rule targets the index.php file I assume (as long as the requisite DirectoryIndex directive is in place), but it does no harm to explicitly state the name within the rule target.

Other than that, what's the problem?
9:31 pm on Jan 15, 2013 (gmt 0)

Preferred Member

10+ Year Member

joined:July 13, 2005
posts: 418
votes: 0


Oops, forgot to mention the actual problem!

As soon as a hyphen appears in the first parameter, I receive a 404; it seems to think it's a different kind of match?

I'm a little worried about saying the URL shouldn't end in a trailing slash, as some of my bigger sites do the same thing (301 if no trailing slash), however all internal links have a trailing slash.
9:34 pm on Jan 15, 2013 (gmt 0)

Preferred Member

10+ Year Member

joined:July 13, 2005
posts: 418
votes: 0


Forgot to add, on this site I also have the follow code before:


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !\.[^/]$
10:43 pm on Jan 15, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


I understand the first condition, but not the second:

If $1 is NOT a literal period followed by a single character that is not a slash followed by nothing (i.e. is "the end").

That code is part of the rule you already posted, I assume.


Many sites have URLs for pages ending with a slash and redirect requests "without slash" to "with slash".

That is the action that should apply to folders.

The HTTP specs define that for pages, URLs do not end with a slash and may have an optional extension.
11:29 pm on Jan 15, 2013 (gmt 0)

Preferred Member

10+ Year Member

joined:July 13, 2005
posts: 418
votes: 0


Regarding the hyphen, I'm not sure exactly what you asking in all honesty; I've built my .htaccess files mainly via other blogs/websites :|
11:46 pm on Jan 15, 2013 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13218
votes: 348


I think I see what you're asking, but let's start by making sure. You have code that rewrites

www.example.com/short-pretty-url-here
to serve content from
www.example.com/index.php?name=short&id=pretty&widget=url&foobar=here

and conversely you change a behind-the-scenes

www.example.com/index.php?name=short&id=pretty&widget=url&foobar=here
into a user-visible
www.example.com/short-pretty-url-here

right? Details don't matter, just the principle.

The problem arises when a query itself contains a hyphen, because then

www.example.com/index.php?name=mixed-up&id=pretty&widget=url&foobar=here
renders as
www.example.com/mixed-up-pretty-url-here

No problem yet. But going in the other direction

www.example.com/mixed-up-pretty-url-here
leads your server to look for
www.example.com/index.php?name=mixed&id=up&widget=pretty&foobar=url

... which sends your php or equivalent into a tizzy. Is that what we're dealing with?
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members