Jump to content

Recommended Posts

Hey,

 

I'm having difficulty getting my htaccess working. I havnt dealt with apache for such a long time a forgot how much I sucked at it.

 

RewriteEngine On

RewriteRule ^old.php$ ^new.php [R,NC,L]

 

This is my first step which I cant seem to get working, i've tried several variations : / I'm not sure if its my hosting or what (I'm with hostgator)

 

Obviously the above should read new.php when user types mywebsite.com/old.php but url should stay the same which would be great. But that doesn't work for me : /

 

So this is embarrasing, very short code and I'm getting nowhere but what am I doing wrong?

 

I ultimatly want to make any requests in /banners/example-user-type for the request to be resent to /banners/createpage.php but url should stay the same as the user typed the first time.

 

Any help goes without saying, you'll be a legend. More stuck than ive been in a long while with this :(

Link to comment
https://forums.phpfreaks.com/topic/272191-htaccess-read-but-dont-redirect/
Share on other sites

1. I can never keep straight whether leading slashes are needed in a particular RewriteRule.

2. The [R] flag will redirect. Since you want the URL to remain unchanged, don't redirect. Also [NC] is probably unnecessary.

3. The replacement URL is not a regular expression - just a regular string.

RewriteRule ^/?old\.php$ new.php [L]

 

As for the banner thing, I take it "example-user-type" can be any arbitrary filename? It's a little harder since you need to include "the request must not actually exist as a file or directory" conditions.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?banners/(.+) banners/createpage.php?banner=$1 [L]

You may want to be more restrictive with the ".+" since that will allow absolutely anything, and you didn't explicitly say so but createpage.php may not need the ?banner= (as far as I know it might look at the original URL automatically).

Hi requinix, thanks for for this my .htaccess definatly now reads

 

RewriteEngine On

RewriteRule ^/?old\.php$ new.php [L]

 

and I also have new.php and old.php

 

yet with this code im recieving a 404 error when i type /old.php and this htaccess code is implemented.

 

I just cant get past this stage could you please check the code mabe its something to do with my account hostgator im not sure :(

Edited by luke777

183.88.244.104 223 /home/lwilson9/public_html/.htaccess a _ o r lwilson9 ftp 1 * c

Wed Dec 19 12:54:27 2012 0 183.88.244.104 218 /home/lwilson9/public_html/.htaccess a _ i r lwilson9 ftp 1 * c

Wed Dec 19 12:54:50 2012 0 183.88.244.104 226 /home/lwilson9/public_html/.htaccess a _ o r lwilson9 ftp 1 * c

Wed Dec 19 12:55:09 2012 0 183.88.244.104 219 /home/lwilson9/public_html/.htaccess a _ i r lwilson9 ftp 1 * c

Wed Dec 19 13:00:27 2012 0 183.88.244.61 222 /home/lwilson9/public_html/.htaccess a _ i r lwilson9 ftp 1 * c

 

I just got this can you make head or tail of it?

 

I logged onto cpanel to check access logs there too but couldnt find any, these are from ftp not sure if relevant

 

yes new.php is 100% in place, i really dont get this..

Edited by luke777

The strangest thing is that when I remove the htaccess code new.php or old.php appears fine. new.php contains "new" old.php contains "old" so the htaccess must be doing something...Just giving me hostgator 404 error page for some reason when the htaccess code is in place though

 

- i realise the code above is ftp logs, cpanel contains access logs but says nothing about a 404 for the new.php doesnt even log it at all while there is other logs there.

Edited by luke777

hey requinix, i just stuck [R] without the L it didnt work with the L aswell. And Im getting a redirect that works. I spoke to hostgator support couldnt give me much info other than 'they dont support scripting errors' Im sure its just an issue with their hosting. I setup 2 free hosting account and it worked on them. So Im just going to have to change host i dont think there is any other solution is there? I need it to run without the address bar changing obviously just old.php to new with no change in url

Edited by luke777

Yes I am using old.php and new.php they are real files in /public_html/ old.php contains <?php echo 'old'; ?> and new.php contains <?php echo 'new'; ?>

 

I just tried the htaccess code for /banners also and got redirected to 404 when I typed mysite.com/banners/any-name into browser : /

 

And of course createpage.php is in place to echo 'createpage' but i see only a 404 error still :|

Edited by luke777
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.