Is this how to use mod_speling? - .htaccess

I had my VPS host enable mod_speling, but I'm not sure it's working, and just wanted to check with you guys that I've got the right idea about it.
I have URLs on the server like this:
https://www.example.com/users/TOMMO/
https://www.example.com/users/JULIE/
People that type URLs using all lower case are getting 404 errors, so I figured enabling mod_speling would fix it. This is what I have in .htaccess:
RewriteEngine On
CheckCaseOnly On
Should this be working?

The mod_speling documentation says this of CheckCaseOnly:
When set, this directive limits the action of the spelling correction to lower/upper case changes. Other potential corrections are not performed.
So that sounds pretty much like exactly what you want. If won't attempt to correct: https://www.mysite.com/users/juliee/ but it will ignore case when you go to https://www.mysite.com/users/JULIE/.
But if you're not using mod_rewrite, you don't need the RewriteEngine On line.

Related

Is this possible with an htaccess rewrite

I am wondering if this is possible to do with an .htaccess rule.
My beginning url:
http://cmfi.org/wherewework/missionary/?missionary=ttaho%2C
What I want to end up with:
http://cmfi.org/wherewework/missionary/ttaho
The ttaho will change according to the page.
Thanks for any input.
Don't think I was asking anyone to code this for me...Just asking if it was possible. I have tried a few things and couldn't get them to work. The %2c is an encoded part of the url that is added from the plugin I was using.
I will figure it out. No worries.

.htaccess rewrite rule from mydomain.com/contact.htm to mydomain.com/contact

I guess this was a very common and simple .htaccess rewrite rule, however I wasn't able to google a solution for it.
So, the question is in the title already, how can I rewrite the address to change it from example.com/contact.htm to example.com/contact? The rule would of course not be only for just the contact.htm but for any page in the website. No need to worry about GET variables, since I won't be using any.
[ Also, do you think this is or might be considered a good practice or not really relevant? ]
Thanks.
Try this:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^contact.htm$ /contact
This should serve contact.html when requesting example.com/contact/
You could consider using MultiViews. You'll need to load the content negotiation module and turn MultiViews on, then Apache will automatically look for a file with an extension (there's a priority list in case you have both .html and .htm files with the same name for instance).

mod_rewrite for name fields

I am complete newbie in mod_rewrite, and I have been going through some sites reading how to handle this, all I could find was when the get variable was numbers and nothing about strings, and it turns out be over my head.
What I want to do is to rewrite display.php?name=blahblah123 to display/blahblah123
Together with the answer, I would love some sites where I can build some grasp over mod_rewrite myself.
Thanks
Edit:
With more searching, I came up with this
RewriteEngine On
RewriteBase /
RewriteRule ^display/([a-z]+)$ display.php?name=$1 [L]
The code above works, but for some reason, The page I get has no CSS. The CSS I see included shows Hostgator's 404 page CSS. But HTML looks fine, so does the content and everything else. Any idea?
Just to be clear, mod_rewrite is something that happens internally in apache. I find that sometimes people do not understand what it does and doesn't do. It will not take a url that you output and change it from
display.php?name=blahblah123
to
display/blahblah123
It will however, allow someone to make a request from your site for display/blahblah123 and convert that to display.php?name=blahblah123, so that your display.php script can operate on it.
Rewrite rules require an understanding of regular expressions. The better you understand regex the easier mod_rewrite will be for you.
As a beginner this article should help: http://www.sitepoint.com/guide-url-rewriting/
For your specific question, I'd probably use:
RewriteRule ^display/([a-zA-Z0-9]+)$ /display.php?name=$1
Try to put a "/" in front of the css file name.
<link rel=".." href="/style.css".
instead of
<link rel=".." href="style.css".

RewriteRule does not match as expected (by me)

i cannot understand why this is not working. Maybe somebody can explain it to me.
I have the following:
http://www.mydomain.de/my-apache-tag.html
which should rewrite to
http://www.mydomain.de/tag/my-apache
In my .htaccess I enabled this rule:
RewriteRule ^/(.*)-tag\.html$ /tag/$1
In my understanding everything between / and before -tag.html should be taken as argument 1.
But the above will lead to a 404. I even put the domain in front of /tag/$1 but this doesn't work too.
Any help is appreciated, thanks much.
Christian
Depending on apache version, the leading slash is not required. (You can place /? if you want to be able to match both cases) see #Jeff Parker comment.
Also, if you want the URL to be displayed as http://www.mydomain.de/tag/my-apache in the browser when typing http://www.mydomain.de/my-apache-tag.html, you should add the [R] flag to redirect.
And of course, your file on the server should be name my-apache in the tag/ directory. Or you will have 404 error.
If you want the client to type http://www.mydomain.de/tag/my-apache and be served http://www.mydomain.de/my-apache-tag.html your rule is wrong and should be :
RewriteRule ^tag/(.*)$ /$1-tag.html
If you want to combine both behaviour, be careful of loops.

Avoiding sub-directory request rewrites with Apache mod_rewrite

I want to a rewrite rule such that if a user goes to the URL example.org/stuff/junk.jpg the rule will process and end up at re-writer.php but if the user goes to example.org/stuff/hackingisawesome/junk.jpg the rule will not be triggered and they will get a standard 404 (or a page, if one should exist).
I can't tell, based on the environmental variables, if this is possible without some fairly fancy regex.
So does anyone know of either:
a) a way this is already built into the mod_rewrite syntax, or
b) a good, reliable way of handling this with regular expressions?
Links to documentation or tutorials welcome. I'm just feeling clueless on where to go next.
Oh, and I can imagine the ways I could simply have the script that the rule redirects to simply deliver the 404, but I'd rather only use the rule when the conditions exist.
Try this:
RewriteRule ^stuff/[^/]+$ re-writer.php
This will rewrite all requests to /stuff/… with only one additional path segment to re-writer.php.

Resources