Welcome to WebmasterWorld Guest from 54.167.29.212

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

URL Rewrite - Hyphen problem

     

Karma

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

10+ Year Member



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?

g1smd

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

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



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?

Karma

9:31 pm on Jan 15, 2013 (gmt 0)

10+ Year Member



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.

Karma

9:34 pm on Jan 15, 2013 (gmt 0)

10+ Year Member



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


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !\.[^/]$

g1smd

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

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



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.

Karma

11:29 pm on Jan 15, 2013 (gmt 0)

10+ Year Member



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

lucy24

11:46 pm on Jan 15, 2013 (gmt 0)

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



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?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month