[solved] Pretty URL's with mod_rewrite not working

Help with getting the CMS CORE package up and running. This does not include 3rd party modules, PHP scripts, anything downloaded via module manager or from any external source.
Locked
cnymike
Power Poster
Power Poster
Posts: 446
Joined: Sun Jan 22, 2006 3:24 am

[solved] Pretty URL's with mod_rewrite not working

Post by cnymike »

I've read of similar problems in the forum but the solutions proposed do not work for me so here goes...

I am able to get Internal Pretty URL's to work.

The problem is that I am unable to get Pretty URL's using mod_rewrite to work.

Here is my .htaccess file:

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# Turns off directory browsing
# not absolutely essential, but keeps people from snooping around without 
# needing empty index.html files everywhere
Options -Indexes

# No sense advertising what we are running
ServerSignature Off

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# URL Filtering helps stop some hack attempts
#IF the URI contains a "http:"
RewriteCond %{QUERY_STRING} http\: [OR]
#OR if the URI contains a "["
RewriteCond %{QUERY_STRING} \[ [OR]
#OR if the URI contains a "]"
RewriteCond %{QUERY_STRING} \] [OR]
#OR if the URI contains a "<__script__>"
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
#OR script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
#OR any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) 
RewriteRule ^.*$ - [F,L] 
# END Filtering

# CMSMS Rewriting
# Set assume mod_rewrite to true in config.php and clear CMSMS cache
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
# END CMSMS
Here is my config.php file:

Code: Select all

#------------
#URL Settings
#------------

$config['assume_mod_rewrite'] = true;
$config['page_extension'] = '.html';
$config['internal_pretty_urls'] = false;
$config['use_hierarchy'] = true;
$config['query_var'] = 'page';
The home page of my site displays, but as soon as I click on any other link, I get a 404 Not Found error

Code: Select all

Not Found

The requested URL /index.php was not found on this server.
If I manually insert an 'index.php' into the URL of the page that generated the error, then the page shows up.

So this is obviously a very simple error in configuration somewhere, but I do not know how to fix it.

I will add the eventual 'fix' to the documentation wiki once I've learned the answer.

thanks.
Last edited by cnymike on Wed Jan 16, 2008 8:14 pm, edited 1 time in total.
moorezilla

Re: Pretty URL's with mod_rewrite not working

Post by moorezilla »

Try getting rid of your [NC]'s at the end of your .htaccess lines. i doubt you need them, and they may be hosing it.

Also... the apache error.log may give you a better idea of errors.

config.php looks ok to me.
cnymike
Power Poster
Power Poster
Posts: 446
Joined: Sun Jan 22, 2006 3:24 am

Re: Pretty URL's with mod_rewrite not working

Post by cnymike »

Removing the [NC] did not help. Removing the [NC] resulted in me getting an error page from my Web Host instead of a page not found error.

Unfortunately I do not have access to the apache error log.
nivekiam

Re: Pretty URL's with mod_rewrite not working

Post by nivekiam »

Try setting:

$config['internal_pretty_urls'] = false;

to true

$config['internal_pretty_urls'] = true;


That's the only setting I can see that is different between yours and mine.

If that doesn't work then I would comment out these lines.  If it works after that, then you can start enabling them 1 by 1 to see what is causing the problem.

Code: Select all

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# URL Filtering helps stop some hack attempts
#IF the URI contains a "http:"
RewriteCond %{QUERY_STRING} http\: [OR]
#OR if the URI contains a "["
RewriteCond %{QUERY_STRING} \[ [OR]
#OR if the URI contains a "]"
RewriteCond %{QUERY_STRING} \] [OR]
#OR if the URI contains a "<__script__>"
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
#OR script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
#OR any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) 
RewriteRule ^.*$ - [F,L] 
# END Filtering
cnymike
Power Poster
Power Poster
Posts: 446
Joined: Sun Jan 22, 2006 3:24 am

Re: Pretty URL's with mod_rewrite not working

Post by cnymike »

nivekiam wrote: Try setting:

$config['internal_pretty_urls'] = false;

to true

$config['internal_pretty_urls'] = true;
But I don't want to use Internal Pretty URL's, I want to use mod_rewrite Pretty URL's. I can't have both set to "true". Or am I just not understanding what you are telling me to do?
nivekiam

Re: Pretty URL's with mod_rewrite not working

Post by nivekiam »

I have both set to true and it works just fine.  Though I just set mine to false and it still works.  So I doubt setting to true for you would fix it.

Did commenting out the URL filtering or the redirect to trailing slash lines work?

EDIT: Also, is CMSms in the root of your site or is it in a sub-directory?
Last edited by nivekiam on Wed Jan 16, 2008 7:32 pm, edited 1 time in total.
cnymike
Power Poster
Power Poster
Posts: 446
Joined: Sun Jan 22, 2006 3:24 am

Re: Pretty URL's with mod_rewrite not working

Post by cnymike »

Did commenting out the URL filtering or the redirect to trailing slash lines work?
No, commenting out everything you suggested did not fix anything.

Hmmm, I just did something to test this on another install I have of CMSMS on the same server

I have another site in a subdirectory of my home directory that mod_rewrite works when I just configured it to use mod_rewrite. So maybe the problem is this...

The problem I have been experiencing is on a site under development that does not have a domain attached to it yet, so I am going in to my web host as

http://myServerName.myWebHost.com/myUse ... imple-1.2/

instead of using, for example, http://www.myDomain.com/cmsmadesimple-1.2/

Do you think this could be the cause of all this? Some sort of Apache thing because I am not using a "real" domain.
nivekiam

Re: Pretty URL's with mod_rewrite not working

Post by nivekiam »

Try setting RewriteBase above all of your ReWrite rules:

# Might be needed in a subdirectory
RewriteBase /myUser/playground/cmsmadesimple-1.2

I have CMSms in a sub-directory of my site for testing and I had to do that.
cnymike
Power Poster
Power Poster
Posts: 446
Joined: Sun Jan 22, 2006 3:24 am

Re: Pretty URL's with mod_rewrite not working

Post by cnymike »

YES! That was it!

Thank you so much for solving this vexing problem. I hope I can repay the favor!

edit: I've applauded  you for that!
Last edited by cnymike on Wed Jan 16, 2008 8:16 pm, edited 1 time in total.
nivekiam

Re: [solved] Pretty URL's with mod_rewrite not working

Post by nivekiam »

Great!  Just remember to change that when you make the site live ;D  (that's bitten me in before too)

I have a feeling you've probably already posted some fix to some problem that I'll come across.
Locked

Return to “[locked] Installation, Setup and Upgrade”