homepage Welcome to WebmasterWorld Guest from 54.166.228.100
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
URL Rewrite - Hyphen problem
Karma




msg:4536280
 8:10 pm on Jan 15, 2013 (gmt 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?

 

g1smd




msg:4536299
 9:10 pm on Jan 15, 2013 (gmt 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?

Karma




msg:4536304
 9:31 pm on Jan 15, 2013 (gmt 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.

Karma




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

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


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

g1smd




msg:4536319
 10:43 pm on Jan 15, 2013 (gmt 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.

Karma




msg:4536328
 11:29 pm on Jan 15, 2013 (gmt 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 :|

lucy24




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

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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved