Forum Moderators: phranque

Message Too Old, No Replies

is it possible to use "RewriteBase's value" as variable?

         

mercedes

2:07 pm on Aug 5, 2010 (gmt 0)

10+ Year Member



Something like...


Options +FollowSymLinks
RewriteEngine On
RewriteBase /hotelspro/dev/regexurl/

RewriteCond %{REQUEST_URI} RWB's VALUE + view

(will match: /hotelspro/dev/regexurl/view)

or is there a trick that can solve this?

jdMorgan

2:26 pm on Aug 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, with the exception of the "flags" used with "file exists checks" only regular-expressions pattern strings may be used on the "right side" of a RewriteCond.

Instead of rushing ahead to discuss a specific implementation, let me ask -- What overall problem are you trying to solve here?

Note also that most Web sites can get along without using RewriteBase at all, unless the server is configured in a non-standard way. You simply put the "base" into the rules and conditions, either as a fixed string or a server variable in the substitution path, and/ or as part of the regular-expressions patterns.

Jim

mercedes

9:27 am on Aug 6, 2010 (gmt 0)

10+ Year Member



there isn't a "problem" actually. i'm just trying to learn mod_rewrite and its benefits; also developing a project at same time.

as a part of this project, i'm planning the url structure.

our project will run at root path whent its done. (example.com/).

in development, i have to run the project in subdirectory. (/hotelspro/).

as you saw in my previous thread, i have some url patterns, like following:

example.com/action/ => action.php

example.com/some/subaction/ => some.php?=subaction=1

example.com/search/?example=1&anotheraxmaple=2 => search.php?={QUERYSTRING HERE}


thats what actually i need.

but i really hate ask questions like that, "can you do this for me?". i prefer to learn it, and do it myself.

could you recommend me a guide/training/book/pdf for learning mod_rewrite?

i tried to get it from apache documentation, but it's pretty complicated.

i'm very pleased for your concern about my questions.

regards.

jdMorgan

3:41 pm on Aug 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see what that has to do with RewriteBase though, which is for use on servers where the hosting comapany 'injects' extra path-info into the filepaths (you could equivalently say that they have configured DocumentRoot incorrectly), and this requires that that path-info be removed to get a pattern match or be re-injected to reach the correct filepath. RewriteBase provides a convenient work-around to do this without requiring this path-info to be coded into all (or many) rules.

The two key pieces of using mod_rewrite successfully and without damage to your site's function, ranking, and traffic are the mod_rewrite directives themselves and the regular expressions patterns that they use. It is necessary to become well-versed in both, and dangerous to proceed without this knowledge. Unfortunately, neither subject is simple, and there are few good, authoritative sources -- I suggest the ones cited in our Apache Forum Charter (one of which is the Apache documentation). There are also several notable threads in our Apache Forum Library, some of which are tutorial in nature.

These sources cover the subjects of mod_rewrite and regular expressions, but what they don't cover is how the two play together in a real server on the Web as it exists today. One of the problems we run into here are that people often ask for code to do something that is "suicidal" when search ranking and/or site usability is concerned. We could provide the code, but that would be doing a disservice to the person asking the question, who does not fully understand *what the code would actually do* to the way his/her site works. We call that "providing the right answer for the wrong question." As an example, people very often ask for code to "redirect this URL to that URL" when what they really want is a URL-to-server-filepath rewrite.

The critical question that must be asked when specifying/planning implementing/coding a mod_rewrite function is, "What will this do to my site in terms of site usability, search engine listings, search engine rankings, and correct operation?"

Being forthright, I have to say that if after implementing a few dozen RewriteRules, it does not become "somewhat easy," then Webmasters should consider hiring someone to do this; Webmasters with limited or no programming skills and no desire to learn them really shouldn't tinker with server configuration code... Everyone must make that assessment for themselves, and I'm not directing this at any one person. However, one single typo or a small logic error can take the site off-line immediately (if you're lucky), or it can sit there, quietly corrupting your search engine listings or destroying your search rankings.

So, I recommend studying hard, defining the requirements thoroughly, coding carefully, taking one small step at a time, and testing, testing, testing.

Jim