View Full Version : .htaccess wild cards or keywords

07-02-2011, 09:37 AM
Hi all,

Is there a way to make a redirect for a filename with no regard to the directory it's being requested in.

so for example, i want to make a redirect for "admin.sys" and i want this redirect to happen no matter where the file "admin.sys" is requested. for example /content/articles/gallery/admin.sys and /admin.sys would both result in the same file being called up.

And if that's possible, how about adding to that, so say i request a file like somerandompage.html followed by "-wildcard" can we then run a php file with a token of the page preceeding the "-wildcard".

An example of a use would be index.html-test "-test" would be the wildcard and would idealy call a specified php file that would run some sort of test on the index.html file.

so this would turn the address bar into a command line of sorts for use in a website admin system of sorts.

Well there you go i have no idea if something like this would be possible with out having all the pages generated by a single php files that would interpret such a request. I would like to use htaccess for this use, as i would not need to have all the overhead of a single managing php file for my whole site.

Happy 4th Everyone!!!

07-07-2011, 06:44 PM
For sure there is a way to do it. I am also trying to do it but unfortunately I am having issues as well. I cannot really understand why my script will not work in achieving this. Is there any tip that you can share that will help me resolve this issue? apologize but I cannot share my code for now.

07-08-2011, 11:34 PM
It's just a matter of pattern matching with Regex. An example of sending all requests for admin.sys (regardless of path) to the same location would be something along the lines of...

RewriteRule admin\.sys$ /foobar.php [L]

In theory the same applies for the tokens, however there is no simple way to max n occurances of something, so you'd have to write n rewrite rules to account for n different amount of flags.

07-11-2011, 08:20 AM
thanks for the info. I can see how it would work for redirecting any page to another page in say another directory.

perhaps i should explain what i'm trying to accomplish. I have a php script that will allow me to edit any page on my site, while looking at the page in the browser. it's very usefull as all changes are done in realtime and on the actual page, so you can really speed the editing side of things up a lot.

The only problem with this functionality is, every single request for a page will include these php options, through an include. So for heavy traffic sites, it can add a lot of processing overhead. Especially since these functions are rarely used, only when editing a page.

So my solution for this is to create another php script that will re assemble any desired page to add the php scripts needed for the editor functionality.

I could go through an admin panel and then navigate to the desired page and that would work fine, but i want to streamline the whole process by allowing me to add a suffix to any standard url. such as my "admin.sys" and then have htaccess redirect the requested url to a specific php file. which will further process the request in the desired manner.

The only thing about this issue is that the original requested URL needs to be processed by the final php file redirected to by htaccess.

So there we go, any ideas.