[solved] pretty url adds extra / in rewrite

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
tonyg
Forum Members
Forum Members
Posts: 80
Joined: Sun Dec 14, 2008 4:54 am

[solved] pretty url adds extra / in rewrite

Post by tonyg »

hi,
i am running 1.11.2 on windows/apache. i am trying to enable pretty urls, but when i do, i have a rewrite issue. the issue is that the rewrite adds a '/' where it should not be:

index.php?page=/index.php

here is the full rewrite log as well as my config.php and apache config

thanks for your help!

rewrite log:

Code: Select all

10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#111b0c0/initial] (2) init rewrite engine with requested uri /
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#111b0c0/initial] (3) applying pattern '^(.+)$' to uri '/'
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#111b0c0/initial] (4) RewriteCond: input='/' pattern='!-f' => matched
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#111b0c0/initial] (4) RewriteCond: input='/' pattern='!-d' => not-matched
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#111b0c0/initial] (3) applying pattern '^(.*)' to uri '/'
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#111b0c0/initial] (4) RewriteCond: input='/' pattern='!/$' => not-matched
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#111b0c0/initial] (1) pass through /
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11210d8/subreq] (2) init rewrite engine with requested uri /index.php
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11210d8/subreq] (3) applying pattern '^(.+)$' to uri '/index.php'
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11210d8/subreq] (4) RewriteCond: input='/index.php' pattern='!-f' => matched
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11210d8/subreq] (4) RewriteCond: input='/index.php' pattern='!-d' => matched
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11210d8/subreq] (2) rewrite '/index.php' -> 'index.php?page=/index.php'
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11210d8/subreq] (3) split uri=index.php?page=/index.php -> uri=index.php, args=page=/index.php
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11210d8/subreq] (2) local path result: index.php
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11270f0/initial] (2) init rewrite engine with requested uri /favicon.ico
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11270f0/initial] (3) applying pattern '^(.+)$' to uri '/favicon.ico'
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11270f0/initial] (4) RewriteCond: input='/favicon.ico' pattern='!-f' => matched
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11270f0/initial] (4) RewriteCond: input='/favicon.ico' pattern='!-d' => matched
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11270f0/initial] (2) rewrite '/favicon.ico' -> 'index.php?page=/favicon.ico'
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11270f0/initial] (3) split uri=index.php?page=/favicon.ico -> uri=index.php, args=page=/favicon.ico
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11270f0/initial] (3) applying pattern '^(.*)' to uri 'index.php'
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11270f0/initial] (4) RewriteCond: input='/favicon.ico' pattern='!/$' => matched
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11270f0/initial] (4) RewriteCond: input='/favicon.ico' pattern='!\.' => not-matched
10.1.1.66 - - [02/Oct/2012:11:18:18 --0400] [www.ultra-fei.com/sid#afd868][rid#11270f0/initial] (2) local path result: index.php
Config.php:

Code: Select all

<?php
$config[''] = '';
$config['dbms'] = 'mysqli';
$config['db_hostname'] = 'db';
$config['db_name'] = 'wwwprod';
$config['db_username'] = 'user';
$config['db_password'] = 'password';
$config['db_prefix'] = 'cms_';
$config['db_port'] = '3306';
$config['timezone'] = 'America/New_York';
$config['root_path'] = 'D:\Websites\WWW';
$config['root_url'] = 'http://www.ultra-fei.com';
$config['ssl_url'] = 'https://www.ultra-fei.com';
$config['url_rewriting'] = 'mod_rewrite';
$config['query_var'] = 'page';
$config['image_transform_lib_path'] = 'D:\Program Files (x86)\ImageMagick-6.7.9-Q16';
$config['page_extension'] = '';
apache config:

Code: Select all

<VirtualHost *:80>
	DocumentRoot "d:/websites/www"
	<Directory "d:/websites/www">
		RewriteBase /
		AllowOverride All
		Options -Indexes
		Order Deny,Allow
		Allow from all
	</Directory>
	DirectoryIndex index.php
RewriteEngine on
	RewriteLog "d:\logs\apache\www-rewrite.log"
	RewriteLogLevel 4

  # Rewrites urls in the form of /parent/child/
  # but only rewrites if the requested URL is not a file or directory
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)$ index.php?page=$1 [QSA]

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

</VirtualHost>
Last edited by tonyg on Wed Oct 03, 2012 2:22 pm, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: pretty url adds extra / in rewrite

Post by Dr.CSS »

A windows server doesn't understand htaccess, from what I know, so the closest you can get is to enable internal pretty URLs in the config.php...

If it does understand the htaccess on your server you may need to add an extension like .html ...
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am

Re: pretty url adds extra / in rewrite

Post by applejack »

Try moving RewriteEngine on above RewriteBase / and comment out DirectoryIndex index.php

Also in the config put $config['page_extension'] = '/';
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: pretty url adds extra / in rewrite

Post by calguy1000 »

This is not a CMSMS issue, its a problem with your .htaccess


Use the sample .htaccess file distributed with CMSMS as doc/htaccess.txt
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
tonyg
Forum Members
Forum Members
Posts: 80
Joined: Sun Dec 14, 2008 4:54 am

Re: pretty url adds extra / in rewrite

Post by tonyg »

applejack,


thanks for your suggestions, I tried both of these
Try moving RewriteEngine on above RewriteBase / and comment out DirectoryIndex index.php
with no success.
i notice that in the log

Code: Select all

10.1.1.65 - - [02/Oct/2012:15:58:56 --0400] [www.ultra-fei.com/sid#42d868][rid#12810d8/subreq] (4) RewriteCond: input='/index.php' pattern='!-f' => matched
10.1.1.65 - - [02/Oct/2012:15:58:56 --0400] [www.ultra-fei.com/sid#42d868][rid#12810d8/subreq] (4) RewriteCond: input='/index.php' pattern='!-d' => matched
10.1.1.65 - - [02/Oct/2012:15:58:56 --0400] [www.ultra-fei.com/sid#42d868][rid#12810d8/subreq] (2) rewrite '/index.php' -> 'index.php?page=/index.php'
10.1.1.65 - - [02/Oct/2012:15:58:56 --0400] [www.ultra-fei.com/sid#42d868][rid#12810d8/subreq] (3) split uri=index.php?page=/index.php -> uri=index.php, args=page=/index.php
10.1.1.65 - - [02/Oct/2012:15:58:56 --0400] [www.ultra-fei.com/sid#42d868][rid#12810d8/subreq] (2) local path result: index.php
it seems index.php matches even though it is a file (!-f), it should fail that logic right?, it still executes the rewrite rule....am i reading that wrong? is there something i would need to do to tell apache (mod_rewrite) that this is a file?

thanks again
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am

Re: pretty url adds extra / in rewrite

Post by applejack »

Try the htaccess file as per Calguy's instructions. If that fails then it is likely to be something in your server configuration.

This is what I use

Code: Select all

#Access file
Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 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]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
tonyg
Forum Members
Forum Members
Posts: 80
Joined: Sun Dec 14, 2008 4:54 am

Re: pretty url adds extra / in rewrite

Post by tonyg »

All, thanks for your help, I think I have it working.
Here is what I found. I was putting the rewrite code in the virtual host block of Apache config. After doing some digging, I found this:
REQUEST_FILENAME
The full local filesystem path to the file or script matching the request, if this has already been determined by the server at the time REQUEST_FILENAME is referenced. Otherwise, such as when used in virtual host context, the same value as REQUEST_URI.
from the Apache docs

What I realized is that although the rewrite rules were getting executed in the virtual host block, at that point, it had not determined the request_filename. as a result, it was appending the uri, which has the / on it.

I dug deeper into the .htaccess and found that Apache for Windows DOES support htaccess, but you probably need to use a different file name. Use the 'AccessFileName ht.acl' directive in the virtual host block to fix this and then I used the stock htaccess file from the docs folder.
It seems to be working now. Thanks again for your help

BTW, Apache seems to recommend NOT using .htaccess files as it slows the page serving down: http://httpd.apache.org/docs/2.2/howto/htaccess.html
Is there any interest in changing the way pretty urls are implemented to avoid using htaccess files? Just wondering.

thanks
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am

Re: [solved] pretty url adds extra / in rewrite

Post by applejack »

Use a Linux based server... ;-)
tonyg
Forum Members
Forum Members
Posts: 80
Joined: Sun Dec 14, 2008 4:54 am

Re: [solved] pretty url adds extra / in rewrite

Post by tonyg »

applejack, to be clear, Apache's recommendation against the htaccess file is platform independent

:P
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: [solved] pretty url adds extra / in rewrite

Post by Dr.CSS »

Might want to read what they say a little closer, notice the 'if', etc...

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.

Most of us don't have access to the "httpd main server config file" or "Directive block"...
Post Reply

Return to “CMSMS Core”