TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-29-2009, 09:53 PM   #1 (permalink)
The Contributor
 
tego10122's Avatar
 
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
tego10122 is on a distinguished road
Default Mod Rewrite Question

Code:
RewriteEngine On
RewriteBase /jay/admin

RewriteRule ^(.*)$ $1.php
I need it to basically do the following

when a user goes to www.domain.com/jay/admin/viewUsers it will call viewUsers.php
__________________
You're Everyday Graphic Artist
Twitter|GigPark|Linked In
Send a message via MSN to tego10122
tego10122 is offline  
Reply With Quote
Old 12-29-2009, 10:22 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Give this a try,

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]


The RewriteCond tells mod_rewrite to ensure that we're not appending the file extension to a directory. The RewriteRule looks for a string that does not already have a period in it, denoting the probability of a file extension. This can be easily modified to allow periods, but check for a three character extension, or to any variety of test situations you would prefer.

Last edited by delayedinsanity : 12-30-2009 at 02:59 AM.
delayedinsanity is offline  
Reply With Quote
Old 12-29-2009, 11:04 PM   #3 (permalink)
The Wanderer
Newcomer 
 
Parvus's Avatar
 
Join Date: Aug 2008
Posts: 21
Thanks: 1
Parvus is on a distinguished road
Default

" www.domain.com/jay/admin/viewUsers it will call viewUsers.php "

The first question I would ask is, to what do you want to redirect exactly ?
www.domain.com/jay/admin/viewUsers -> www.domain.com/jay/admin/viewUsers.php
or would you like:
www.domain.com/jay/admin/viewUsers -> www.domain.com/viewUsers.php

Let's asume you mean case 1.
The easiest would be:
Code:
RewriteEngine On
^(http://www.domain.com/jay/admin/viewUsers)$ $1.php
But let's make it a bit cleaner than that =P
Code:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
^(.+)/viewUsers$ $1/viewUsers.php
# or even better:
#^(.+)/(\w+)/?$ $1/$2.php
#/? means that /viewUsers/ will also be redirected (notice the / on the end)
There are loads of combinations possible, it all depends on what you exactly need.
If you only need to redirect 1 specific url the upper code will do just fine. Want to redirect more url's who have the same base ? Than the RegEx will help you =]
Parvus is offline  
Reply With Quote
Old 12-29-2009, 11:27 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

I guess I assumed he was just hiding the extension. Didn't dawn on me to ask if it was just for the one file. :)
delayedinsanity is offline  
Reply With Quote
Old 12-30-2009, 02:27 AM   #5 (permalink)
The Contributor
 
tego10122's Avatar
 
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
tego10122 is on a distinguished road
Default

he first question I would ask is, to what do you want to redirect exactly ?
www.domain.com/jay/admin/viewUsers -> www.domain.com/jay/admin/viewUsers.php
__________________
You're Everyday Graphic Artist
Twitter|GigPark|Linked In
Send a message via MSN to tego10122
tego10122 is offline  
Reply With Quote
Old 12-30-2009, 03:11 AM   #6 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

RewriteEngine On
RewriteBase /jay/admin

RewriteRule ^viewUsers$ viewUsers.php [NC,L]

You might find this useful too.
delayedinsanity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Answer Then PHP Question codefreek The Lounge 14 07-20-2009 07:19 PM
Need help of Mod Rewrite kokjj87 Advanced PHP Programming 3 02-22-2009 06:08 PM
Mod Rewrite question (vb related) Brook General 1 01-20-2008 08:14 PM
Cleaning data before entering database question Killswitch General 7 12-24-2007 11:29 PM
Important Database Structure Question! AnthonyOS MySQL & Databases 5 12-20-2007 03:26 PM


All times are GMT. The time now is 08:00 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design