BenSeagrave
11-08-2009, 10:29 AM
Hey,
How can i get my urls to look nice, Not to look like example.com/folder/file.php but to look like example.com/folder/file I think it's with .htaccess, Another thing though that say if on the file page i had more items so it would go to example.com/folder/file/morefiles So the file page couldn't be a page, here is a example of what i mean:
http://modernwarfare247.com/weapons
and then when you click an image
http://www.modernwarfare247.com/weapons/sub-machine-guns
I hope you get what i mean, Thanks
NeilAgg
11-08-2009, 10:31 AM
You can use 303 redirects to do that.
BenSeagrave
11-08-2009, 10:52 AM
Can you tell me what to do?
Like instructions all most :P
NeilAgg
11-08-2009, 10:56 AM
Take a look at the Apache doc
http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect
mwatkins
11-08-2009, 01:33 PM
Oooh, unclean URL space / showing implementation details (php extensions) is so... 1999!
Unfortunately for you trying to solve this is something of an exercise in futility unless you control all the source code and/or are willing to modify same and maintain it forever. Links hard coded in your application will still have .php extensions. Maybe good enough for you to have those clicked links resolve to an "apparently" .php-less path, but it isn't ideal.
Yes, using mod_rewrite or mod_redirect you can redirect a click on those links to a destination which *appears* to have no file extension, but you still have all those links in your app regardless.
Something like this in .htaccess *may* do the job:
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]
If not careful with these types of band-aid solutions it is easy to end up with problematic situations like multiple URLs responding with the same content (a SEO no-no) or worse.
Better yet to run applications that have been built for nice url's from the get-go. This isn't rocket science - many web developers have been doing this for a decade now.
FreeKill
11-08-2009, 02:38 PM
Here's a link to a good cheat sheet for mod_rewrite:
http://www.addedbytes.com/apache/mod_rewrite-cheat-sheet/
Energizer Bunny
11-10-2009, 12:38 AM
Hey,
How can i get my urls to look nice, Not to look like example.com/folder/file.php but to look like example.com/folder/file I think it's with .htaccess, Another thing though that say if on the file page i had more items so it would go to example.com/folder/file/morefiles So the file page couldn't be a page, here is a example of what i mean:
http://modernwarfare247.com/weapons
and then when you click an image
http://www.modernwarfare247.com/weapons/sub-machine-guns
I hope you get what i mean, Thanks
Hmm the thing that comes to mind is using zend framework or some mvc based scripting, maybe use .net mvc stuff ?
WHP123
11-11-2009, 05:43 PM
I see your webpage is Joomla based. There are alot of plugins which do what you want. The one I personally use along with the basic Joomla settings when I create pages for people is SH404SEF. Google it and install it. Also in Sh404SEF you can remove the "generator" Meta. Thats NOT good to have there because bots search the net for that and then begin hacking if you are not 100% uptodate.
online-business-cook
11-12-2009, 10:59 PM
yeah, use a plug-in unless you actually like doing all that deep code stuff.
HostBill
11-17-2009, 08:33 AM
I think joomla as well as many other cms-es using htaccess as well, so its good to learn how to use it for further development.
Most of such implementations uses:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
Lines like that which basicly redirects all the queries to one file - index.php, and all magic happens there.
How to fast parse it for addresses like: /part1/part2/part3 ? Simple:
$requestURI = explode('/', $_SERVER['REQUEST_URI']);
$scriptName = explode('/',$_SERVER['SCRIPT_NAME']);
$commandArray = array_diff_assoc($requestURI,$scriptName);
$commandArray = array_values($commandArray);
Now in $commandsArray will look like:
array([0]=>'part1',[1]=>'part2',[2]=>'part3')
And now its your choise what to do with it;]
BH-Greg
11-17-2009, 08:56 AM
Don't mind if I take a look at this, I think this is good so you can hide your file names and etc. Thanks for sharing the information guys.