Forum Moderators: phranque
It is possible? and Can I make some exceptions for the rule. Like jus tdo it for files in a certain folder?
PS: The site is all static with some SSI. No CGI.
I really appreciate your help.
Thanks a lot,
Yan
This Introduction to mod_rewrite [webmasterworld.com] thread may serve as a good introduction to rewriting URLs. While we are happy to help you debug your code, we generally prefer not to write your code for you, as stated by our charter [webmasterworld.com].
In order to keep the threads posted here valuable to more than just one person or a very few people, we prefer to discuss Apache configuration, .htaccess, and mod_rewrite, rather than to provide a free code-writing forum. We would much prefer to help you learn to write the code yourself if that's what you want. If not, posting your specific requirements in the Commercial Exchange [webmasterworld.com] may help you to find a contractor to write the code for you for a reasonable fee.
Take a look at the mod_rewrite thread cited above, and please post any questions you may have.
Jim
Let me make something clear that might help. We could do this in 2 ways.
1 - The links points to a file without extension href=file1 , but we can do that the file itself has the extension.shtml . So what we need to do is just add the extension to the link, not to the file
2 - Both file and links have no extension
so href=file1 will open file1 but will be dysplayed as a .shtml .
Maybe all we need to do is actually change the parser.
Thanks
{On my site I have a URL} poker.shtml. The links point to file called "card-game".
The way it is now, it will actually open file card-game, but it's considering that it's just a txt file, while it actually is a SHTML, there are some SSI in there.
So, I want to try a way to make every call to file card-game in a way that the server will parse it as a shtml file.
OR
The other idea is, I rename card-file to card-file.shtml. Then what I need to do is make a htaccess that will add extension .shtml to the link "card game" pointing to card-game (with no extension).
See what I mean?
Thanks all for helping.
[edited by: jdMorgan at 6:08 am (utc) on Nov. 22, 2003]
[edit reason] No specific URLs, please [/edit]
I would recommend solution number 2 from your post, msg#8 above. Rename the actual files with a .shtml extension. This will eliminate the need for the AddHandler directive.
Then, you will need to rewrite all pathnames *that are not* (sub)directories or all pathnames *that are* files to add the .shtml extension. (There may be other reasons you don't want to do this, but rewriting this way will be inefficient, so you might want to consider using a multi-file search-and-replace editor to fix all the links on your site quickly and easily.)
The key is to use the -f flag of RewriteCond to check the filepath to see if it is a file or a directory. If the requested resource is a file, and its URI contains no period (therefore no file extension), then add .shtml. This will add overhead to every file you serve, though.
# If local URL contains no periods
RewriteCond %{REQUEST_URI} ^([^\.]*)$
# If requested filename is a file, not a directory
RewriteCond %{REQUEST_FILENAME} -f
# Add .shtml extension
RewriteRule ^(.*)$ /$1.shtml [L]
Jim
Could you let me know what code I have to add if I also want it to place an underscore "_" where there are spaces on the file names?
so that file called this if file 1 , be renamed to this_is_file_1
but, it needs to be a rewrite. Like on the browser it would also show the underscores?
Is it possible?
Thanks again.
# if the URI doesn't contain a dot and doesn't contain a slash
^([[b]^\./[/b]]+)/?$ /$1.shtml [L]
Jim
Now, to change spaces to underscore. I saw the other topic.
But, is there a code for space, or I can just use a space like that:
RewriteRule ^([^_]*)_([^ ]*)$ http://www.example.com/$1_$2 [R=301,L]
?
[edited by: jdMorgan at 2:34 am (utc) on Nov. 24, 2003]
[edit reason] De-linked URL [/edit]
I'm afraid you DO want to match a dot. You want to match it, and then take action only if there is *no* dot present. I am not telling you that you have a logic problem, I am telling you that you have a syntax error.
The regular expression "[^.]" will match only blank URLs because it says "NOT any single character". Because any non-blank URL will contain at least a single character, only a blank URL will match that pattern.
Similarly, the pattern "[^./]" will match only a blank URL because the match still fails if *any* character is present, and therefore, adding the slash does nothing.
To match URLs that do not contain a dot or a slash, you need "[^\./]" or "[^/\.]".
If you want to match a dot or a space or any character in the list below, either positively (character is present) or negatively (character is not present), you must precede it with a backslash "\"
.+*?^$%(){}[]\¦ or <space>
To match a space in a URL (example /blah blah.html), use ^blah\ blah\.html$
Ref: [etext.lib.virginia.edu...]
Jim