homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
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

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


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

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


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)

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)

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)

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)

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)

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)

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

to serve content from

and conversely you change a behind-the-scenes

into a user-visible

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

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

renders as

No problem yet. But going in the other direction

leads your server to look for

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