Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8350341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:17:16+00:00 2026-06-09T08:17:16+00:00

I have this link: http://mysite.com/subdirectory/something/stuff/index.php What regex would I be able to use that

  • 0

I have this link:

http://mysite.com/subdirectory/something/stuff/index.php

What regex would I be able to use that matches only the first slash so that I am able to extract everything behind it using the $1 or $2 variables that represent found items? So that it would return “subdirectory/something/stuff/index.php”.

For example, I thought of using this regex:

(.*)/(.*)

But that keeps repeating for each slash so it will only return the last part (in this case index.php) of the url when I use $2.

The language I’m using it with is apache (?), it’ll go in a .htaccess file.

Thanks in advance!

EDIT:
Ok, so the background on this is that I have some files in the subdirectory linking to other files using links like “/files/test.php”, because those files expect the other directories to be in the root folder, but on my site they aren’t. So I thought of using the htaccess file to redirect those requests to the root folder to the subdirectory so everything works. And replacing all the links is not an option because there are more than a thousand of them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:17:20+00:00Added an answer on June 9, 2026 at 8:17 am

    Try this regular expression (it will redirect to the subdirectory stuff only if the requested file does not exist, so if it exists it won’t loop infinitly) :

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ sub/stuff/$1 [NC,L,R=301]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to do this refering to following link. http://skypher.com/index.php/2008/07/28/function-list-for-php/ But no success.
I have this link which i need to translate in a php variable. http://www.facebook.com/dialog/apprequests?app_id=346824075388300&to=1149862205&message=Facebook+Dialogs+are+so+easy%21&redirect_uri=http%3A%2F%2Fpenelope-ns.net%2Ffb%2F
am using the application in this link http://www.jeasyui.com/tutorial/app/crud2.php .I have added one more column
I have a link http://mysite.com/myname which shows the profile page.. But if i use
Let's say I have a links like this: http://mysite.com?i=343435&f=224&u=334 and this link is constant
I have a site like: http://*mysite.com/search/ in it index.php is generating History.pushState() for history.js
I have found this link: http://www.jfree.org/forum/viewtopic.php?f=3&t=6314 Its back in 2007 where they agree that
I have installed Qt for windows CE using this link http://qt.nokia.com/products/platform/qt-for-windows-ce for visual studio8,
i have a jquery slider, link: http://ekallevig.com/jshowoff/ this is my html code: <div id=features>
Lets say I have a String: Go to this page: http://mysite.com/?page=1 , and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.