The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 16, 2019, 05:30:25 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: mod_rewrite help needed  (Read 3485 times)
Bertje
Rookie
**
Offline Offline

Posts: 17


View Profile
« on: April 14, 2009, 03:28:27 AM »

Hi All,

I need some help with an .htaccess file.
I'm trying to rewrite the index.php to the domain root, but this site has a CMS that is using the index.php to perform certain functionalities.

Normally I would use this, but I can't since some functions will stop working if I do:
Code:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://mysite.com/ [R=301,L]

I tried this, but it doesn't work:
Code:
RewriteCond %{IS_SUBREQ} false
RewriteRule ^/index\.php$ http://mysite.com [R=301,L]

Any ideas?
Logged

No links in signatures please
Bompa
Administrator
Lifer
*****
Offline Offline

Posts: 564


Where does this show?


View Profile
« Reply #1 on: April 14, 2009, 03:36:18 AM »

index.php should already BE the domain root, if not there's a different directive to set it, i think.

so you're saying the domain root is index.html or what?

Bompa
Logged

"The most beautiful and profound emotion we can experience is the sensation of the mystical..." - Albert Einstein
Bertje
Rookie
**
Offline Offline

Posts: 17


View Profile
« Reply #2 on: April 14, 2009, 04:27:42 AM »

Hi Bomps,

Sorry for lousy explanation. Index.php is indeed the root. I'm just trying to rewrite the url, so that 'mysite.com/index.php' is rewritten to 'mysite.com'
Logged

No links in signatures please
Bompa
Administrator
Lifer
*****
Offline Offline

Posts: 564


Where does this show?


View Profile
« Reply #3 on: April 14, 2009, 06:01:17 AM »

Hi Bomps,

Sorry for lousy explanation. Index.php is indeed the root. I'm just trying to rewrite the url, so that 'mysite.com/index.php' is rewritten to 'mysite.com'

Like you don't want index.php to show in the browser?

Logged

"The most beautiful and profound emotion we can experience is the sensation of the mystical..." - Albert Einstein
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #4 on: April 14, 2009, 06:42:47 AM »

Code:
RewriteRule ^index\.php$ / [R=301,L]
Logged

hai
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #5 on: April 14, 2009, 06:57:34 AM »

Classic problem - I can never remember this one - thanks VS, I've now got a neat place to  bookmark.

Cheers,

DM
Logged
Bertje
Rookie
**
Offline Offline

Posts: 17


View Profile
« Reply #6 on: April 14, 2009, 07:51:09 AM »

Indeed, I don't want to show index.php in the browser.

Unfortunately Vsloathes solution doesn't work.  Sad
Logged

No links in signatures please
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #7 on: April 14, 2009, 08:11:08 AM »

Remove the R=301

Just make it so the URL appears as / even though they're still seeing index.php

OH DUH

^/index.php$

Slash in front. Request URI always starts with a slash. No need to escape the dot if you don't want to.

EDIT: I might just be really dumb. I haven't checked those rewriterules so let me know what happens.
Logged

hai
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #8 on: April 14, 2009, 08:53:17 AM »

let me guess. you are using expression engine?

regardless though.

Code:
RewriteEngine On
RewriteBase /

#strip WWW
RewriteCond      %{HTTP_HOST} ^www\.(.*)
RewriteRule      ^(.*)$   http://%1/$1   [R=301,L]

#strip index.php from URL - Expression Engine
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

that will also deal with shit after the index.php
assuming you still want it.

if it is EE and you need any help at all, thats my CMS of choice and I know that thing pretty damn well.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Bertje
Rookie
**
Offline Offline

Posts: 17


View Profile
« Reply #9 on: April 14, 2009, 11:19:52 AM »

grr.... nope, that doesn't do the trick.

This piece of code works great:
Code:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.mysite.com/ [R=301,L]

But, when I use this, some functions like
Code:
<form action='index.php' .... blah>
stop working.
« Last Edit: April 14, 2009, 11:33:49 PM by Bertje » Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #10 on: April 14, 2009, 11:43:00 AM »

Bertje - the challenge I think on your last example is that index.php is a relative URL rather than hard, and it might be showing up in the rewrite differently. Do you have access to the httpd.conf, or just the .htaccess? If you can get to the httpd.conf, OR you can get your host to add a directive to your virtual host in the httpd.conf, then you can debug pretty easily.

A couple ways. The best best way would be for them to allow you access to your own VirtualHost settings by moving your VH to a separate file that you have access to and then getting them to Include it. Then you can edit it yourself rather than having them involved. This is rather aggressive though and they may not be ameable.

You could also ask them to add
RewriteLog /home/bertje/rw.log
RewriteLogLevel 10

to your VirtualHost, and then you'd get a pretty verbose output of exactly how the Rewrite engine is trying to do your rewrite (the real problem is that you're poking at issues blindly here).

Regarding your existing code, I am not able to test at the moment but you are trying to evaluate a hard URL but sending a relative (as I mentioned above) ... perhaps if you simply duplicate the condition you'd get what you want:

Code:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.bertjepenispills.com/ [R=301,L]

... or perhaps just ditching the / in any case, but I don't know if that would break something else.
« Last Edit: April 15, 2009, 12:32:13 AM by Bompa » Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Bompa
Administrator
Lifer
*****
Offline Offline

Posts: 564


Where does this show?


View Profile
« Reply #11 on: April 14, 2009, 06:05:30 PM »

grr.... nope, that doesn't do the trick.

This piece of code works great:
Code:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.bertjepenispills.com/ [R=301,L]

But, when I use this, some functions like
Code:
<form action='index.php' .... blah>
stop working.


RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/

I've really never seen anything like that before.

But anyways, you are putting VS's code *below* all the CMS's rules, right?

I think if you could share the CMS's rules with VS, or NB, or perk, they could
figure this out for you, but you might have reasons not to share it.


My last resort suggestion would be to have conditions that negate all
the CMS's conds and rules. In other words, the CMS's code says "If
it matches this pattern, do this stuff".  Below that I would try "If it
does NOT match (same patterns), drop the "index.php".

htaccess is difficult enough when I have it in front of me, but when I
can't see what's already in it, it's almost impossible to deal with.

Bomps

« Last Edit: April 15, 2009, 12:32:48 AM by Bompa » Logged

"The most beautiful and profound emotion we can experience is the sensation of the mystical..." - Albert Einstein
Bertje
Rookie
**
Offline Offline

Posts: 17


View Profile
« Reply #12 on: April 15, 2009, 04:39:30 AM »

Thanks for your help all. I still haven't got it working, but I'll follow Perks advise and see if I can get some help from my host.

Cheers,
B
Logged

No links in signatures please
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!