mod_rewrite problem

Hi all,

This isn’t my strong area. I’ve pulled down a friend’s website and have set it up on my development server so I can mess around with it.

The site’s original .htaccess looked like this:

RewriteCond %{HTTP_HOST} !^www\.sitename\.com.au
RewriteRule ^(.*)$ http://www.sitename.com.au/$1 [R=permanent,L]

RewriteRule ^([a-zA-Z0-9-]+)(/)$ /index.php?page=$1
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)(/
)$ /index.php?page=$1&second=$2
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)(/)$ /index.php?page=$1&second=$2&third=$3
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/(\+.
)(/*)$ /index.php?page=$1&second=$2&third=$3&forth=$4

But I have it hosted on an apache temporary URL that looks like this:

http://myserver/~sitename

I’ve been playing around with the .htaccess but can’t work out how to get it working. Any help would be greatly appreciated.

Tay,

Yup! You’re still missing Last flags on your RewriteRules #2 - #5 so EVERYTHING after #2 can NEVER match (they are ANDed by default). Since you KNOW that PHP won’t work when you fail to terminate a statement or close a block statement, why would you expect mod_rewrite to work?

What are your test URLs? What version of Apache?

Regards,

DK

Hi,

Sorry I left a bit out - should be:

RewriteCond %{HTTP_HOST} !^www\.sitename\.com.au
RewriteRule ^(.*)$ http://www.sitename.com.au/$1 [R=permanent,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R,L]

RewriteRule ^([a-zA-Z0-9-]+)(/)$ /index.php?page=$1
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)(/
)$ /index.php?page=$1&second=$2
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)(/)$ /index.php?page=$1&second=$2&third=$3
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/(\+.
)(/*)$ /index.php?page=$1&second=$2&third=$3&forth=$4

does that help? :smiley:

tay,

Test URI(s)? Apache version? WHERE are your Last flags for RewriteRules #2 - #5?

Regards,

DK

I didn’t write the htaccess - its up and it works for the current site.
{snip}

New website location URL {snip}

My server doesn’t reveal the apache version. I tried phpinfo:
SERVER_PROTOCOL HTTP/1.1
SERVER_SIGNATURE no value
SERVER_SOFTWARE Apache

All I want to do is adjust the htaccess so the site works at the new location.

Wow.

You are the kind of arrogant biggot that give “IT people” a bad name. You’re the kind of guy a company employees and sticks him in dark room to sit down, shut up, make sure everything works and for god’s sake don’t talk to anyone.

Let’s have a look at my original post -

This isn’t my strong area. I’ve pulled down a friend’s website and have set it up on my development server so I can mess around with it.

The site’s original .htaccess looked like this:

You see that? I didn’t write it. Its come from a live, working website. And “this isn’t my strong area”

But I have it hosted on an apache temporary URL that looks like this:

http://myserver/~sitename

You immediately come back asking me all questions related to htaccess files that I naturally have no idea about.

You say “If it’s up and works for the current site, what’s the problem?”

See here:

All I want to do is adjust the htaccess so the site works at the new location.

Is that hard to understand?

More important, if you’re using someone else’s code, WHY DON’T YOU KNOW WHAT IT’S DOING?

It rewrites php URLs to SEO friendly URLs. I know what it does.

You then tell me phpinfo isn’t good enough for you and rewrite the code with red comments all through it like my primary school homework.

You know what I did in the end? I just put the site on a subdomain and made these changes:


RewriteCond %{HTTP_HOST} !^sitename\\.SUBDOMAIN\\.com.au
RewriteRule ^(.*)$ http://sitename.SUBDOMAIN.com.au/$1 [R=permanent,L]

And guess what smarty pants? It works. So I’m sure there was a simple solution despite all the validation errors in the htaccess but you felt this was a great time to beat your chest or keyboard or something like that? And the funny thing is I know nothing about this stuff but I knew the first two lines I posted were where I could fix my problem.

I was completely appreciative and courteous to you for taking interest in my thread. If you don’t want to help people, just do everyone a favour and piss off.

I can’t help but notice you still haven’t answered the three questions dklynn has asked you 2 times now. So I’ll ask them for the third time :wink:

  • What are your test URI(s)? i.e. What is the URL input and what should be the output of the rewrites?
  • What Apache version are you running?
  • WHERE are your Last flags for RewriteRules #3 - #10? (was #2 - #5, but you added more rules and didn’t add the Last Flag to those as well …)

tay,

If “it’s up and works for the current site,” what’s the problem?

More important, if you’re using someone else’s code, WHY DON’T YOU KNOW WHAT IT’S DOING? :nono:

Okay, that’s a pet peeve of mine!

R is a directive (flag) to send a code other than 303 (temporary redirection) to the requester (search engine?).

L is the directive to stop processing that mod_rewrite block, i.e., to stop ANDing mod_rewrite statements. THAT is the flag which is the equivalent to ; or } and, IMHO, must NOT be ignored!

Please enclose your code in the code wrapper, the <> button or type your own brackets like [ code ] … [ /code ] (without the spaces in the brackets).

ErrorDocument 404 /page-not-found
[COLOR="Magenta"]# is page-not-found a file which can be served?[/COLOR]
#ErrorDocument 404 http://www.someothersite.com.au/
[COLOR="Blue"]# see what not using the code wrapper does - automatic link parsing![/COLOR]

RewriteEngine on 

[COLOR="Blue"]# enforce www. on domain 
[/COLOR]RewriteCond %{HTTP_HOST} !^www\\.sitename\\.com[COLOR="Blue"]\\[/COLOR].au 
RewriteRule ^(.*)$ http://www.sitename.com.au/$1 [R=[COLOR="Blue"]301[/COLOR],L]

[COLOR="Blue"]# strip trailing / - [/COLOR][COLOR="Red"]but this should NOT be done on a directory, too[/COLOR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [[COLOR="Red"]R[/COLOR],L]
# R or R=301?

# CMS
RewriteRule ^espot/?$ /espot/index.php [R]
[COLOR="Red"]# AGAIN, NO LAST FLAG![/COLOR]
RewriteRule ^site/?$ /espot/index.php [R]
[COLOR="Red"]# DITTO!
# optional trailing / after removing trailing slashes?
# delete the /? before the end anchors![/COLOR]

# Dynamic Sitemap
RewriteRule ^sitemap.xml$ /main-sitemap.xml.php
[COLOR="Red"]# AGAIN, NO LAST FLAG![/COLOR]

# Blog RSS
#RewriteRule ^blog.atom.xml$ /blog__/blog.atom.php
[COLOR="Red"]# AGAIN, NO LAST FLAG![/COLOR]

RewriteRule ^([a-zA-Z0-9-]+)(/*)$ /index.php?page=$1
[COLOR="Red"]# AGAIN, NO LAST FLAG![/COLOR]
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)(/*)$ /index.php?page=$1&second=$2
[COLOR="Red"]# AGAIN, NO LAST FLAG![/COLOR]
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)(/*)$ /index.php?page=$1&second=$2&third=$3
[COLOR="Red"]# AGAIN, NO LAST FLAG![/COLOR]
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/(\\+.*)(/*)$ /index.php?page=$1&second=$2&third=$3&forth=$4
[COLOR="Red"]# AGAIN, NO LAST FLAG![/COLOR]

phpinfo() is far more informative than that! You can also create a PHP script to read the version value of the Apache server (www.php.net) and STILL no test URIs.

Regards,

DK

David,

Thank you being patient with me. I had left some more parts that I thought were irrelevant to my issue but I have included the comlpete htaccess in full this time. Sorry I’m learning as I go here. I understand what [R] is now :).

ErrorDocument 404 /page-not-found
RewriteEngine on 

RewriteCond %{HTTP_HOST} !^www\\.sitename\\.com.au 
RewriteRule ^(.*)$ http://www.sitename.com.au/$1 [R=permanent,L]

#ErrorDocument 404 http://www.someothersite.com.au/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R,L]

# CMS
RewriteRule ^espot/?$ /espot/index.php [R]
RewriteRule ^site/?$ /espot/index.php [R]

# Dynamic Sitemap
RewriteRule ^sitemap.xml$ /main-sitemap.xml.php

# Blog RSS
#RewriteRule ^blog.atom.xml$ /blog__/blog.atom.php

RewriteRule ^([a-zA-Z0-9-]+)(/*)$ /index.php?page=$1
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)(/*)$ /index.php?page=$1&second=$2
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)(/*)$ /index.php?page=$1&second=$2&third=$3
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/(\\+.*)(/*)$ /index.php?page=$1&second=$2&third=$3&forth=$4

Thanks again for your assistance.