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

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

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

Postby tdekker » Tue Sep 08, 2009 5:44 am

Hello, Im making an offline version for a website im redesigning. But that site makes use of .htacces and that is new to me. I looked a bit around. made a bit of changes but cant get it to work correct.

The .htaccess file is as followed.
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]+) /index.php?name=$1 [PT]


in httpd confic i used to have the basic setup.

#LoadModule rewrite_module modules/mod_rewrite.so (I removed the # from there)

And changed Options Indexes FollowSymLinks Includes ExecCGI to
Options +FollowSymLinks which made it look like that (removed the comments)

Code: Select all
<Directory "C:/Program Files/xampp/htdocs/">
    Options +FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>


All i can see is the index.php Every other option i try ends up in page does not exsist.

At the online version it is doing what it should do, so it has to be something in the httpd.conf that needs to get changed.

Can anyone please help me out and tell me what to change.

Thank you in advance
tdekker
 
Posts: 9
Joined: Tue Sep 08, 2009 5:34 am

Postby richardk » Tue Sep 08, 2009 8:05 am

And changed Options Indexes FollowSymLinks Includes ExecCGI to
Options +FollowSymLinks which made it look like that (removed the comments)

Change it back, it already has FollowSymLinks set.

All i can see is the index.php Every other option i try ends up in page does not exsist.

For example?
Does this mod_rewrite test work?

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !^(INNOmgr|templates|balk|Image|pages|afbeelding|medicmail|Medi-Mail)(/.*)?$ [NC]
RewriteRule ^([a-z]+)/?$ /index.php?name=$1 [NC,QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby tdekker » Tue Sep 08, 2009 11:09 am

Thanks thats been usefull and also made me feel like a fool a bit.

I ran the test in that link befor I had changed it. After it got changed it didnt work. But because I didnt restarted the browser I was still able to be in or something like that.

Anyways. Its doing something more now and that is good.

That piece of code that you placed made the /templates change to /templates?name=templates. Which helps me a lot since now I get how they were able to use a $GET to use with that.

I changed the htaccess to the one it used to be and it works nice there, going to the pages it should if those are entered.

There is however still a minor problem.

If I enter something that is covered with
RewriteCond %{REQUEST_URI} !(INNOmgr|templates|balk|Image|pages|afbeelding|medicmail|Medi-Mail)
It gets changed like it should. But if I type something random fdsa it doesnt change the header and just says page not found, While on the original side with spam like that it goes to the layout with nicely covered, the page you are looking for is not one on this site.

So something I can do to make random entries change as well with this as htaccess

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]+) /index.php?name=$1 [PT]


It is as if it just skips these steps
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_URI} !^.(jpg|gif|css)
tdekker
 
Posts: 9
Joined: Tue Sep 08, 2009 5:34 am

Postby richardk » Tue Sep 08, 2009 4:45 pm

What are you trying to match? ^([a-zA-Z]+) means match anything that starts with letters.

If I enter something that is covered with
RewriteCond %{REQUEST_URI} !(INNOmgr|templates|balk|Image|pages|afbeelding|medicmail|Medi-Mail)
It gets changed like it should.

Change? Anything listed in that condition should cause the RewriteRule to not match.

But if I type something random fdsa it doesnt change the header and just says page not found

Set up a custom 404 ErrorDocument
Code: Select all
ErrorDocument 404 /index.php?name=404_error


Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Ignore these directories.
RewriteCond %{REQUEST_URI} !^/(INNOmgr|templates|balk|Image|pages|afbeelding|medicmail|Medi-Mail)(/.*)?$ [NC]
# Match URLs that only contain letters.
RewriteRule ^([a-z]+)/?$ /index.php?name=$1 [NC,QSA,L]


Or
Code: Select all
Options +FollowSymLinks

RewriteEngine on

# Ignore the /index.php file.
RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
# Ignore all .css, .gif and .jpg files.
RewriteCond %{REQUEST_URI} !^/.+\.(jpg|gif|css)$ [NC]
# Ignore these directories.
RewriteCond %{REQUEST_URI} !^/(INNOmgr|templates|balk|Image|pages|afbeelding|medicmail|Medi-Mail)(/.*)?$ [NC]
RewriteRule ^([a-z]+) /index.php?name=$1 [NC,QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby tdekker » Tue Sep 08, 2009 11:54 pm

Ok I did some more testing.
And I am sure i saw the name=templates etc last time I tried it, but its not there anymore this time. Which in fact is a good thing. Each time I see better what it is all supposed to do and I now know exactly what should be happening.

How it should go.

Everything with these vallues dont get changed.
Code: Select all
RewriteCond %{REQUEST_URI} !index.php
   RewriteCond %{REQUEST_URI} !^.(jpg|gif|css)
   RewriteCond %{REQUEST_URI} !(INNOmgr|templates|balk|Image|pages|afbeelding|medicmail|Medi-Mail)

As it is now, thats working good.

But everything that doesnt meet those vallues should get changed in
www.domain.com/index.php?name=(inserted name) But in the header it should look like www.domain.com/(inserted name)

And that is not happening.

If I enter a header with index.php?name=oplossingen it goes to the page it should with that. (oplossingen is a value in the database that then gets called because they use a $GET to grab it out the header)
And if i used something that is not in the database then it doest find the value and it goes to the 404_error document. Like it should.

But that only happens if i type it in with index.php?name=.....
It has to happen when it gets entered without that.




I also used your examples. First one does /?name=... behind the things in that line, like templates/?name=templates, But doest change it if other things get entered.
Second one makes the site not work

I think that it just doesnt add the /index.php part or something. Like it ignores that.



Here is my httpd.conf file (removed the comments) Perhaps that can be of some use to solve it.

Code: Select all

ThreadsPerChild 250
MaxRequestsPerChild  0

ServerRoot "C:/Program Files/xampp/apache"

Listen 80

LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
because of mod_autoindex_color.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dav_module modules/mod_dav.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule include_module modules/mod_include.so
LoadModule info_module modules/mod_info.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule status_module modules/mod_status.so
LoadModule ssl_module modules/mod_ssl.so

LoadModule autoindex_color_module modules/mod_autoindex_color.so

ServerAdmin admin@localhost

ServerName localhost:80

DocumentRoot "C:/Program Files/xampp/htdocs"

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>


<Directory "C:/Program Files/xampp/htdocs/">
     Options Indexes FollowSymLinks Includes ExecCGI
     AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

<IfModule dir_module>
    DirectoryIndex index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.shtml index.phtml
</IfModule>

<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
</FilesMatch>

ErrorLog logs/error.log

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog logs/access.log common

</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "C:/Program Files/xampp/cgi-bin/"
</IfModule>

<Directory "C:/Program Files/xampp/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

DefaultType text/plain

<IfModule mime_module>
   TypesConfig conf/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    AddHandler cgi-script .cgi

   AddType text/html .shtml
   AddOutputFilter INCLUDES .shtml
</IfModule>

EnableMMAP off
EnableSendfile off

Include conf/extra/httpd-multilang-errordoc.conf

Include conf/extra/httpd-autoindex.conf

Include conf/extra/httpd-languages.conf

Include conf/extra/httpd-userdir.conf

Include conf/extra/httpd-info.conf

Include conf/extra/httpd-vhosts.conf

Include conf/extra/httpd-manual.conf

Include conf/extra/httpd-dav.conf

Include conf/extra/httpd-default.conf

Include conf/extra/httpd-ssl.conf

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
tdekker
 
Posts: 9
Joined: Tue Sep 08, 2009 5:34 am

Postby richardk » Wed Sep 09, 2009 12:17 pm

Ignore the /templates/?name=templates redirect. It was dine by mod_dir because the trailing slash was missing.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine on

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?name=$1 [QSA,L]


Here is my httpd.conf file (removed the comments) Perhaps that can be of some use to solve it.

It looks fine.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby tdekker » Wed Sep 09, 2009 11:56 pm

The last thing you told me to try doesnt give the right end result either.

It shows index.php.
I can go to templates without it adding anything extra to the header.
Anything not in that line shows the blank, page does not exsist thing from IE.

Basically the same result as the origional .htaccess keeps giving.

I really do think that the origional .htaccess is one that should give the desired end result. Because it works with that in the online version of the site. Just not on the offline version on my laptop.
tdekker
 
Posts: 9
Joined: Tue Sep 08, 2009 5:34 am

Postby richardk » Thu Sep 10, 2009 7:28 am

I really do think that the origional .htaccess is one that should give the desired end result.

It's not a well written mod_rewrite.

It shows index.php.

Then i don't understand the problem. Go to /doesn't exist. Load index.php.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby tdekker » Thu Sep 10, 2009 8:39 am

richardk wrote:Then i don't understand the problem. Go to /doesn't exist. Load index.php.


Ok didnt quite follow that last part. Where do I have to go?

Im guessing you want my index.php

Thats not that big. You probably want the functions.php, that one is big. And if you do want it, i prefer to continue in pm, befor I show the entire scripting of the website. Not too sure if the companie would approve of that.

Code: Select all
<?php

$blocked = Array ();
$blocked[] = '66.79.166.3';

if (in_array ($_SERVER['REMOTE_ADDR'], $blocked))
{
exit;
}

   include ("includes/db_connect.php");
   include ("includes/functions.php");

   $site = show_site ($page_title, $image);
   $header = tpl_header ("", false, $page_title, $image);
   $feeter = tpl_feeter ();

   echo $header . $site . $feeter;

?>
tdekker
 
Posts: 9
Joined: Tue Sep 08, 2009 5:34 am

Postby richardk » Thu Sep 10, 2009 2:33 pm

Then i don't understand the problem. Go to /doesn't exist. Load index.php.

Ok didnt quite follow that last part. Where do I have to go?

Im guessing you want my index.php

I explained it really badly. You said "It shows index.php.". That is what the RewriteRule does, it sends requests, like /doesn't-exist, to index.php.

On your laptop, if you go to /richardk, does the index.php file get processed?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 39 guests

cron