Note that i have other folders like backoffice and blog
Contents in backoffice should be accessed normally like this siteurl/backoffice/myaccount.php only the contents in pages folder should be affected
@John_Betong i followed the link and i tried something like this
#CHANGE SOME STATIC PAGES URL FOR THE PAGES FOLDER USING PRETTY URLS
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^pages/([a-zA-Z0-9-]+)(/?)$ /$1
Yet nothing works, all i wanted is not to have my contents in my pages folder accesed like this /pages/contact.php i want it to look as if the files where inside the root folder even though is kept in a subfolder called pages.
Even if i have to use pretty urls method to rewrite each of the pages one by one i dont mind since they are static files, someone should please point me to the right direction so that example.com/pages/contact.php will be accessed like this example.com/contact.php
The RewriteRule you have there does it the other way around, it says, "any request for /pages/whatever should go to /whatever)`.
But since you want it the other way around we should put this other way. But that poses a problem, because then everything under / will be served from /pages, and I don’t think that what you want.
So, what we could do instead is:
If the URL exists in /, serve that
If the URL doesn’t exist, see if it exists in /pages
If it does exist in /pages, serve that
In code that would be
Options +FollowSymlinks -MultiViews
RewriteEngine On
# If the requested file does not exist in /
RewriteCond %{SCRIPT_FILENAME} !-f
# And the request is not for existing directory
RewriteCond %{SCRIPT_FILENAME} !-d
# And the requested file does exist in pages/
RewriteCond pages/%{SCRIPT_FILENAME} -f
# Then serve the requested file from pages/
RewriteRule ^(.*)$ /pages/$1
Alternatively you could actually move all files from /pages to / and then put redirects on the old URLs to new URLs. That’s easier configuration wise and better from a SEO point of view, as you’re actively indicating to search engines the files moved, instead of just serving them from some place else all of a sudden and leave it up to the search engines to draw their own conclusions from that. What if their conclusions are wrong and that has negative consequences on your rankings?
Thanks @rpkamp
I will try the code you sent and update you, i know moving all the files to the root saves us this headache but on the other hand i have read articles stating only some files should be kept in the root, even though i don’t know the security thats offers and they never told us how to handle issues like url, bcs it makes no sense having this vital pages called like this example. com/pages/contact.php
I think the place you said serve the requested file from pages supposed to be serve the requested pages from root,
That is if file found in pages folder then serve it from /file.php
I would be tempted to adopt the modern practise of using the htaccess script to redirect everything to /index.php. Tests can then be tried and if the file exists in the pages directory then include the file and exit. If it is not in the pages directory and in another blog directory then include and exit… If it does not exist then show or include an error or search page.
@John_Betong this sounds highly technical to me but if it is a modern pratice as you pointed out then let me see the code and apply it,
But pointing everything to index.php how is that possible? Also won’t this affect folders like images, js, css or backoffice
Thanks we have all tried, but nothing seems to work, i think i should adopt a new strategy using file_get_contents(),
As this will be more better to use but i want know if there is a security issue with using it in an index.php file to call other pages?
If no security issues then is my safe bet than using .htacess rules that is not working
Can you please elaborate on what part of the code I provided earlier doesn’t work?
Also, just because it won’t work the first time doesn’t mean Apache doesn’t support it. It certainly does, we just need to find instructions for it.
That’s what @John_Betong is aiming at, and that’s good thing to strife for, but first I’d clean up your URLs up by moving the files to the correct spot. Once you’ve done that you could as a second step rewrite everthing to only entry point. But as always, changing two things at once it not a good idea, because then when something breaks you won’t know which of the two changes caused it.
Exactly my point, the rewrite is getting so confusing that i dont understand how my files structures are , if it works using some advanced method it may give me issues debugging it
@John_Betong code was first printing strict warning must be called first, which i did and then when i view some pages the codes are printed as text in front page
The supplied scripts were tested on my computer and worked fine.
More information is required rather than “it does not work”.
If the htaccess file was used and no changes then was the index.php file called?
Edit
If the message returned was “strict messages must be called first” then additional script has been added to the file, causing the error. Please use only the script supplied and make sure there are no hidden spaces before <?php
The index.php printed the codes, m
Since yours worked on your local machine, and the file structure is same with mine, then zip it and send to me as attachment so i can follow it up, i think thats best way.
Just two folders, and a page in the pages folder i will try it out. I fixed the issue of strict warning.