Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite wildcard directories

setting up a wildcard url pages

         

advancedgraphix

7:19 pm on Feb 25, 2008 (gmt 0)

10+ Year Member



What I'm looking to do is this

www.domain.com/name
to point to www.domain.com/folder_name/index.php

Which would allow me to do this, but they all point to the same index file.

www.domain.com/name1
www.domain.com/name2
www.domain.com/name3

RewriteRule ^([^/]+)/index\.php$ /folder_name/$1 [L]

Also want it to work with both trailing slash / and without...

This works to the sense that anything in the root dir will point to the location of the folder name... :( I only want the names I specity. I appreciate any help here :)

jdMorgan

9:49 pm on Feb 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It seems to me that the description of the goal is internally inconsistent, and the rule doesn't resemble either possible interpretation of the goal.

Please provide an explicit list of at least three full URLs (use example.com, please) and their corresponding filepaths.

Being specific will help you define the problem more clearly, and help you get a more useful response as well.

One thing that helps is to indicate what parts of the desired filepath(s) are fixed, and what parts are variable, for example, here's one possible interpretation of your description:

Requested URL .......... actual server filepath
example.com/name<0-9> -> /folder_name<0-9>/index.php
-or-
example.com/name<0-9>/ -> /folder_name<0-9>/index.php

In this case, "name", "/folder_name", and "/index.php" are literal strings, while the name-number is to be copied from the URL to the filepath.

Jim

advancedgraphix

10:33 pm on Feb 25, 2008 (gmt 0)

10+ Year Member



For ex. www.example.com/Las-Vegas, so only the city would change, which would use www.example.com/Nevada/index.php, no matter what city I will change it to, I need it pointing to the same location, same index.php file.

The description you outlined above was on track :) That's what I'm trying to do. Hope this makes it a bit more clear.

This seems to be doing to trick, but will not work without the trailing slash /

RewriteRule ^([^/]+)/$ /Nevada/index.php?cityid=$1 [L]

jdMorgan

1:28 am on Feb 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can make the slash optional, then...

RewriteRule ^([^/]+)/?$ /Nevada/index.php?cityid=$1 [L]

but be aware that you now have two URLs (one with and one without the trailing slash) which resolve to the same content, which is not recommended. Though there is a lot of fear and unreasonable doubt about so-called "duplicate-content penalties," this much is true: Allowing more than one URL to resolve to the same content can result in incoming links to both URLs, and the resultant splitting of the PageRank/Link-popularity of that content across the multiple URLs, resulting in lower ranking in search results.

In some cases, the search engines will get around to discovering that the two URLs actually point to the same page, and they will discard one of the URLs... BUT...They pick which one to keep, not you.

Taken to extremes of dozens or hundreds of duplicates, there may indeed be an actual penalty invoked, but in most cases, the "penalty" is simply self-inflicted ranking dilution as described above.

Whether (sub)domains, protocols, URL-paths, or query string formats, it is best to accept one and only one URL and permanently redirect all other variations to that one "canonical" form.

Jim

advancedgraphix

9:08 pm on Feb 26, 2008 (gmt 0)

10+ Year Member



One of the problems with RewriteRule ^([^/]+)/?$ /Nevada/index.php?cityid=$1 [L] is that anything in the root points to my /Nevada/index.php location, it seems that it only works when I take the ? away, the version with / works. Calling a dir directly like /fckeditor/ also doesn't work, unless I do full url /fckeditor/index.php.

So I don’t know if it is possible to check, if a dir exists go there, otherwise go to the /Nevada/index.php location, and ignore anything in the root /index.php or /file.php

I also would like both versions with or without the / slash, because somebody that will type that in will get the page and not a page not found error. I would do a 301 permanent redirect on the version without to the version with.

jdMorgan

5:54 am on Feb 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See RewriteCond -- specifically using the -d and -f tokens. Used to test %{REQUEST_FILENAME} and/or %{DOCUMENT_ROOT}%{REQUEST_URI}/ these directory and/or file exists checks can come in very handy... :)

A more efficient way to do this is to put "Nevada" into a "virtual" subdirectory called (for example) "states" which makes the need for the rewrite explicit, instead of having to check your disk for files and directories on every URL request.

Jim