Need help with .htaccess and what to change in httpd.conf

New to mod_rewrite? This is a good place to start.

Postby tdekker » Mon Sep 14, 2009 12:53 am

No if I type something like /richardk then it just says. The page /richardk does not exist. It doest even go to index then.

The only pages that it can find are the ones that also exist as a filename. If the filename is not there then it doest understand it. While the online version does.
tdekker
 
Posts: 9
Joined: Tue Sep 08, 2009 5:34 am

Postby richardk » Mon Sep 14, 2009 10:01 am

Then it doesn't wound like the mod_rewrite is processed at all.

Put
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine on

RewriteRule ^abc /index.php?name=$0 [QSA,L]

in your .htaccess file and go to /abc123, do you get sent to index.php?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby tdekker » Mon Sep 14, 2009 11:26 am

Also not sending me to index.
Its as if it just doesnt understand the rewrite rule. Or that is just takes priority over the entered link and if thats not there, then it just gives up.
tdekker
 
Posts: 9
Joined: Tue Sep 08, 2009 5:34 am

Postby richardk » Tue Sep 15, 2009 6:06 pm

What happens if you replace QSA with R and go to /abc123? Also try it without the ^.
Are you sure this mod_rewrite test works?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby tdekker » Fri Sep 18, 2009 5:47 am

Ok the test works, always did.

But I did find something interresting. I changed QSA to R and with /abc123 it changed the header in

from
http://localhost/software-connection/public_html/abc123
too
http://localhost/index.php?name=abc

And I think that is also the whole reason why it keeps messing up. Because there is nothing to find at localhost. The reason the origional code seems to work is because there it is right after the domain, which can be seen as localhost here.
tdekker
 
Posts: 9
Joined: Tue Sep 08, 2009 5:34 am

Postby tdekker » Fri Sep 18, 2009 5:51 am

I changed the origional rewrite rule to this

RewriteRule ^([a-zA-Z]+) software-connection/public_html/index.php?name=$1 [PT]

And now the page does work like it should.
Thanks very much for all the help on this.

Btw, you said it was a badly written htaccess in the first place?

If so, what would be best to rewrite this too?
Code: Select all
    Options +FollowSymLinks
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_URI} !index.php
   RewriteCond %{REQUEST_URI} !^.(jpg|gif|css)
   RewriteCond %{REQUEST_URI} !(INNOmgr|templates|balk|Image|pages|afbeelding|medicmail|Medi-Mail)
   RewriteRule ^([a-zA-Z]+) software-connection/public_html/index.php?name=$1 [PT]


And would it be possible that there is a way for it to work without having to add the software-connection/public_html. Im guessing not. Will just have to remind myself, and the company to pay attention when they move some files. They have to be carefull with the connect.php anyways so doesnt matter if its not possible.
tdekker
 
Posts: 9
Joined: Tue Sep 08, 2009 5:34 am

Postby richardk » Fri Sep 18, 2009 9:47 am

I changed the origional rewrite rule to this

RewriteRule ^([a-zA-Z]+) software-connection/public_html/index.php?name=$1 [PT]

...

And would it be possible that there is a way for it to work without having to add the software-connection/public_html. Im guessing not.

So the .htaccess and index.php files are in C:/Program Files/xampp/htdocs/software-connection/public_html/? If you remove the RewriteBase (you should anyway) a relative path would probably work, too.

Also, you could set up your test server to allow multiple document roots: FAQ: Testing many websites on your development computer/server.

Btw, you said it was a badly written htaccess in the first place?

I am quite picky as you will see.
Code: Select all
^([a-zA-Z]+)

This means the rule will match any URL that starts with a letter, you probably want to limit it a bit more than that.
Code: Select all
!index.php

This means it will not match any URL that contains "indexanycharacterphp". Notice the anycharacter because the "." is a special regular expression character matching any character. If you want to only match a literal "." it needs escaping with a "\", ie. "\.". Also, the "indexanycharacterphp" can appear anywhere, eg. newindex.php5.
Code: Select all
!^.(jpg|gif|css)

Because of the ^, which means the beginning, and the fact you are using REQUEST_URI which always begins with a /, this will (! not) match /jpg*, /gif* and /css*. I'm guessing you wanted to match file extensions.

Code: Select all
!(INNOmgr|templates|balk|Image|pages|afbeelding|medicmail|Medi-Mail)

Again, these will match anywhere in the URL, so a request to /specialpages would not get rewritten. I'm guessing these a sub directories?

Code: Select all
[PT]

The PT flag does not work in .htaccess files. You should use the L (Last) flag instead so the processing stops when the rule matches and possibly the QSA (Query String Append) flag so query strings are passed on, eg. /abc?def=ghi to index.php?name=abc&def=ghi.

If so, what would be best to rewrite this too?

That depends on what you want to match.

If you only want to match /letters then
Code: Select all
  Options +FollowSymLinks

   RewriteEngine On

   RewriteCond $1 !^(INNOmgr|templates|balk|Image|pages|afbeelding|medicmail|Medi-Mail)$
   RewriteRule ^([a-z]+)/?$ ./index.php?name=$1 [NC,QSA,L]

should be fine.

Edit: changed RewriteCond in last [code].
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Previous

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 33 guests

cron