Forum Moderators: phranque
I have a web address as this :
[mysite.co.uk...]
My .htaccess file not allows me to view above as this :
[mysite.co.uk...]
However ideally I would like to virtually remove the 'sites' from the url, so :
[mysite.co.uk...]
TBH ideally i would like also to create a virtual subdomain :
[london.mysite.co.uk...] something similar.
I would really appreciate any help on this matter, even if it is just to remove the sites folder.
My .htaccess file is as follows:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)/(.*) viewsites.php?name=$1&page=$2 [L]
I have searched and searched for a solution, but everything i try seems to give me a 'page cannot be found error'
many thx
jon
You'll likely also want to support the "If-Modified-Since" requests from clients. To make a long story short, removing this bit of path information will mean that your script will have to handle many more requests, and will become much more complicated as a result. And if you have other extensionless URLs that are NOT 'sites,' then there really is no solution short of redesigning your entire URL architecture and URL layout. The '/sites' path information is something that appears to be needed to make your site work properly.
(You could change '/sites' to some other 'word' if you like, as long as that word is fairly unique.)
BTW, a more robust and *much* more efficient rule for your existing setup would be:
RewriteRule ^([^/]+)/([^/]+)$ viewsites.php?name=$1&page=$2 [L]
Jim
I think i get the 'jist' of what you are saying, and appreciate your reworking of my .htaccess file. I will put that into practice.
I wish i had thought about the urls before i started coding the site, my other big problem is knowing very little about .htaccesss rewrite rules.
My obvious solution would be to move the viewsites.php file out of the 'sites' folder and into the root. This would eliminate my problem, BUT (along with other problems i will face including the php basedir) I don't know how to get the .htaccess to work. I can't seem to just move it into the root folder where i would have thought it would work.
Oh well, i'll keep trying. But appreciate if you have any further thoughts
many thx
jon.
RewriteRule ^sites/([^/]+)/([^/]+)$ sites/viewsites.php?name=$1&page=$2 [L]
Jim
Before I try that I moved viewsites.php into the root, then copied the original .htaccess out of the sites folder and into the root also.
The problems were: the style sheet refused to work and the images, even thought the links to both are not relative.
Secondly (and most important) it messed up all my other files, not just in root but also in other folders. For instance the root index.php was stripped of any css and was trying to send vars to the database. (as viewsites does).
I will try your above suggestion now though.
Sorry for not being exactly clear, it is difficult to explain properly when you are a novice and don't know the terminology
cheers
jon
As you know i'm would ideally like to remove the sites folder from the address bar.
viewsites.php is in the sites folder. When I move this file into the root the .htaccess file messes up all the other pages within the whole domain.
Please let me know if more info is required.
many thx
jon
[edited by: jdMorgan at 8:15 pm (utc) on July 13, 2009]
[edit reason] Sorry, no links to personal sites. [/edit]
If you don't do that, then your original rule, moved to example.co.uk/.htaccess will rewrite *any* requested URL-path of the form
/<anything or nothing>/<anything or nothing>
to viewsites.php?name=$1&page=$2
Your external CSS files, images, external JavaScript files, and other included objects will not work unless you refer to them as <img src="http://www.example.co.uk/<path-to-image-directory>/image-name.gif">
or as <img src="/path-to-image-directory>/image-name.gif">
and exclude those paths from being rewritten to your script as well. (Note that this is what 'sites/' is doing for you now.)
That is, you must use a canonical URL or a server-root-relative URL-path (starting at "/" -- the home directory or your site).
Realize that it is the client (e.g. the browser) that resolves relative URLs to canonical URLs. It does so based on the 'page address' URL showing in its address bar. So if you are rewriting URLs to a different directory level, the browser will be basing its requests on the directory level in its address bar, and will be requesting images from that directory -- unless you give it a canonical or server-relative (and not a page-relative) include path.
If you've got all these included-object paths right and still have a problem, it may be due to browser caching -- Be sure to completely flush (delete) your browser cache before testing any new server-side code.
Again, you can change 'sites/' to something else in the address bar, or make it "sites-" instead of "sites/", but if you delete it completely you may well regret it. Realise that it is only "sites/" that is telling your server (via mod_rewrite) to pass the request to the "viewsites" script. If you remove that information from the URL, then viewsites.php will be the only script you can ever have... only... one... ever... forever... unless you change your domain or are willing to give up all of your hard-earned links and search rankings.
This is a big bad bear waiting to bite you, and I suggest you reconsider 'cosmetics' versus the severely-limited future of your site. If you want to replace "sites" with a shorter string or a "better keyword," then go for it. But be very very careful about how completely-eliminating it will affect your options for further developing your site in the future.
Now, if you'd be satisfied to limit yourself to one and only one script on this site forever, or some very-inefficient solutions that may well force an early upgrade to a dedicated server, we can discuss other options, but I want you to mentally 'sign off on that' before assisting in what I consider to be a very bad idea.
One option might be:
RewriteRule ^([^/]+)/([^/.]+)$ viewsites.php?name=$1&page=$2 [L]
The only restriction with that is that your 'page' names may not ever contain a period or a slash.
Jim
I take everything you have said onboard and will take your advice to leave it 'as is', or re-code the site to remove the sites folder.
It is a relatively new site and is just a freebie I am creating for submariner association branches, just so they can have a presence on the www and hopefully generate further membership.
I was looking for a simple quick way of making the addresses easier to remember and friendly, but tbh it isn't that bad.
many many thx again
kindest regards
jon