Well I've driven myself crazy enough that I finally had to break down and ask for some help.
I have a simple rewrite rule in my .htaccess file in a folder called "myfolder"
RewriteEngine On
RewriteBase /myfolder/
RewriteRule ^([^/.]+)/?$ index.php?page=$1 [L]
If the url is /myfolder/home
In the index.php file located in "myfolder" I simply call
if (isset($_GET['page'])){$page = $_GET['page'];}else{$page = 'home';}
//then I include the content for requested page using
include('pages/'.$page.'/content.php');
//NOTE: I have checks to see if the page exists in the final code, but for now I am keeping it simple trying to track down this issue
If I print_r($_GET); It shows Array ( [page] => home )
So it works as expected and the page content loads, but if I look in the browser error console I see a php error and when I click on the error I see Array ( [page] => df )Warning: require(pages/df/content):
For some reason it's thinking that page = df and I can't for the life of me figure out why. Does it have to do with a rewrite loop or something?
Any help is much appreciated. Thanks in advance.
Ok I finally figured it out. I had a page.js file I was including that I thought was blank (long story why I'm including it) but it actually had "df" in it. I guess the combination of the file being named page.js and garbage javascript caused all kinds of havoc.
Oh the joys of coding never cease do they haha.
Thanks anyway guys.
PS I'll make this answered after the two day limit is up.
Related
I had a folder that contained 15000 images, i decided to put them in 10 folders.
The initial folder url where i had my 15000 images was :
www.mysite.com/images/games/
And the new folders' urls are :
www.mysite.com/images/games/1/
www.mysite.com/images/games/2/
www.mysite.com/images/games/3/
www.mysite.com/images/games/4/
www.mysite.com/images/games/5/
www.mysite.com/images/games/6/
www.mysite.com/images/games/7/
www.mysite.com/images/games/8/
www.mysite.com/images/games/9/
www.mysite.com/images/games/10/
How can I redirect my images to match their correct folder to get rid of 404 errors?
Given your expansion in the comments above:
I know which images go to which folder, but its a big list
I suggest putting that list in a text file, and using find and replace (or awk?) to transform that list into mod_redirect rules, e.g.
Redirect /images/games/oldname /images/games/8/oldname
Then paste those into a configuration file. If there's no actual algorithm that determined how these got sorted into directories, there's no program that can redirect requests, because it would require a formula to work from.
Much as I love to cite When Not To Use Rewrite, this is actually a case where mod_rewrite is called for.
You don't say how you distributed your images between the ten new directories, but I am assuming the images were numbered (e.g. 00001.png, 00002.png, ... 15000.png). Then you used the last digit to determine which image goes into which folder, i.e. 00001.png goes into the 1 directory, all the way up to 15000.png which goes into the 10 directory (I think - why didn't you name it 0?) That's what you did, right?
You don't mention what server you're using on this site, so I'm going to assume you're using Apache, right? In that case you'd edit the appropriate configuration file (I started trying to assume which one, but honestly it could be any one of four I can think of, depending on whether you have edit rights to the vhost configuration, or root on the server, or if you're on a Debian-flavored or Red-Hat-flavored distro, you are using Linux, right? You didn't say.) You'd make sure there's a RewriteEngine On in there somewhere, then you'd do something like this:
RewriteRule ^/images/games/(\d+)(\d)\.png$ /images/games/$2/$1$2.png
...except that you named the directory 10 instead of 0, so all the ones ending in 0 are going to get misdirected. Maybe we should try this?
RewriteRule ^/images/games/(\d+0)\.png$ /images/games/10/$1.png [L]
RewriteRule ^/images/games/(\d+)([1-9])\.png$ /images/games/$2/$1$2.png [L]
...and catch the 0s first, then everything else.
I'd check this answer, but you haven't given us anywhere near enough information to know how.
I've seen many cases of these rewrite questions but I don't get all the regular experessions and browser errors and such so I was hoping that someone could help me.
Ok, so I have a file with a url variable 'pages.php?p=foo' and I would like to rewrite it so that it appears as 'foo.html' in the same directory.
I was thinking along the lines of:
RewriteRule (.+).html pages.php?p=$1
The trouble is, the browser displays 400 Bad Request errors.
I'm hoping there's a fix for this but I can't get my head around it.
Any help is much appreciated :)
Try this:
RewriteRule (.*)\.html pages.php?p=$1
I've made a website, and page links are formed like this: ?page=projects_project1.
I want the pages to be accessible this way as well: projects/project1. So ?page= should be removed, and _ should be replaced by /... So what's being accessed now using ?page=projects_project1, should become accessible at projects/project1...
What do I need to put in my .htaccess file to achieve this? Please also explain how it is done, so I can do it myself next time.
Try this out:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([^/]+)/([a-z0-9_]+)$ index.php?page=$1_$2 [NC,L]
The first line says that it should follow the symbolic links that may exist, the second line actually switches on the RewriteEngine and the third matches links that look like the following:
anything_except_a_forward_slash/anything_here_that_is_an_alphanumeric_or_forward_slash
Hi i hve been running forum for quite while and people started using it for spam etc and now even though i took it down i still got like 100 clicks day for threads that dont exist and the forum is not existing too.
I tired of seeing this crap in my piwik stats i want to move it with mod rewrite so every time someone access
site.com/samples/forum he goes soemwhere else like actual redirect to fbi.com etc. better without showing my url of couse or just to some non existing folder so it does not triger my stats.
You're probably looking for something along the lines of:
RewriteEngine on
RewriteRule /samples/forum http://othersite.com/path [L,R]
(of course can flex if you need patterns, or for different paths) There are tons of handy options that you can use, all documented in Apache's documentation.
I'm currently working on an overhaul of my blog site, and have found a way to convert all my current pages into static html pages. They are currently using friendly url's which remap to a central index.php page with GET parameters attached on.
The change I am trying to make is have those same friendly URL's map to their html counterparts. I am currently using this rule:
RewriteRule ^archives?/([^/]+)/([^/.]+)/?$ archives/$1/$2.html
The error log is reporting that it cant find blah.html/ which means it's looking for the .html directory, instead of the .html file. So a better example:
/archives/2009/original-name
should be getting mapped to
/archives/2009/original-name.html
but is really getting mapped to
/archives/2009/original-name.html/
What am I missing here?
don't you need to use it the other way around? I didn't test the code but it should be something like this:
RewriteRule ^archives/(.*)/(.*).html archives/$1/$2
I can't see anything obviously wrong with your regex.
At a guess I'd say you might have a rule somewhere following this, which is redirecting anything without a trailing slash to its equivalent with the slash (a common thing to do to avoid duplicate content issues).
You didn't escape your period in the 2nd statement. Try this.
RewriteRule ^archives?/([^/]+)/([^/\.]+)/?$ archives/$1/$2.html