Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 16th, 2008, 02:41 PM
pfwd.tech's Avatar
pfwd.tech pfwd.tech is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2005
Location: UK
Posts: 556 pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)  Folding Points: 27514 Folding Title: Starter FolderFolding Points: 27514 Folding Title: Starter Folder
Time spent in forums: 6 Days 8 h 58 m 25 sec
Reputation Power: 81
Send a message via Google Talk to pfwd.tech Send a message via Skype to pfwd.tech
Most not start with must end with

Hi I'm looking for a mod rewrite pattern that will redirect a user to /testdir/ if the url doesn't start with /start/here/ and ends with .php
Also each directory in the url must go after /testdir/
Examples
URL: /user/one/two/three.php
Redirect: /testdir/user/one/two/three

URL : /start/here/one/two/three.php
Redirect :false no redirect

This is what I have so far:
Code:
^(^(\/start\/here\/\))(.*).php$ /testdir/$1 [R=301,QSA,L] 


This doesn't work
Can anyone suggest anything?
__________________

Reply With Quote
  #2  
Old October 16th, 2008, 03:48 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,683 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 2 h 49 m 16 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Code:
RewriteRule ^/?((?!start/here).*|.*(?<!\.php)) /testdir/$1 [R=301,QSA,L]

Try that.

[edit] I interpreted what you said to mean there should be a redirection if it doesn't start with "start/here" OR the request doesn't end with ".php"

Reply With Quote
  #3  
Old October 17th, 2008, 04:04 AM
pfwd.tech's Avatar
pfwd.tech pfwd.tech is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2005
Location: UK
Posts: 556 pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)  Folding Points: 27514 Folding Title: Starter FolderFolding Points: 27514 Folding Title: Starter Folder
Time spent in forums: 6 Days 8 h 58 m 25 sec
Reputation Power: 81
Send a message via Google Talk to pfwd.tech Send a message via Skype to pfwd.tech
Quote:
Originally Posted by requinix
Code:
RewriteRule ^/?((?!start/here).*|.*(?<!\.php)) /testdir/$1 [R=301,QSA,L]

Try that.

[edit] I interpreted what you said to mean there should be a redirection if it doesn't start with "start/here" OR the request doesn't end with ".php"

Sorry i meant it doesn't start with start/here but it needs to end with .php
My latest is try is:
RewriteRule ^/?((?!start/here).*(\.php$)) /testdir/$1 [R=301,QSA,L]

I want to redirect any url which doesn't start with /start/here/ but end with .htm
I also need to add anything inbetween / and .htm to /testdir

My above example redirects from
/test/test/x.htm
to /testdir/testdir/testdir/x.htm
It warns of a redirect loop and crashes out

i need it to redirect to
/testdir/test/x/

Reply With Quote
  #4  
Old October 17th, 2008, 04:37 AM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,683 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 2 h 49 m 16 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
How about
Code:
RewriteRule ^/?(?!testdir|start/here)(.*\.(php|html?))$ /testdir/$1 [R=301,QSA,L]

If it doesn't start with start/here and it's a PHP or HTML file (added the optional 'l' just to be safe) it's redirected to testdir.

Reply With Quote
  #5  
Old October 17th, 2008, 04:37 AM
pfwd.tech's Avatar
pfwd.tech pfwd.tech is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2005
Location: UK
Posts: 556 pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)pfwd.tech User rank is Second Lieutenant (5000 - 10000 Reputation Level)  Folding Points: 27514 Folding Title: Starter FolderFolding Points: 27514 Folding Title: Starter Folder
Time spent in forums: 6 Days 8 h 58 m 25 sec
Reputation Power: 81
Send a message via Google Talk to pfwd.tech Send a message via Skype to pfwd.tech
I have it working:
Code:
RewriteRule ^/?(?!start/here)(.*)(\.php$) /testdir/$1 [R=301,QSA,L] 

A condition checks if the url doesn't start with start/here
It places all the bits after that to $1 and checks that it ends with .php
and then it all hte bits is $1 after /testdir/
Yippee I have it working

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Most not start with must end with

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap