Forum Moderators: phranque
My first post, but have visited this board before when looking for tips and tricks.
Im working with mod_rewrite, trying to remove the string '/directory/' from the [QSA] but since im a newbie all im getting is a huge headache.
so basically in pseudo code:
1. var1=get query string
(var1 is now '/directory/#*$!x'
2. var1=var1 with '/directory/' removed
(var1 is now 'xxxx'
3. call someurl?param=var1
The line below is what i am trying to modify:
RewriteRule ^(.*) index.php?rewrite=on&_mod_rw_url_=$1 [QSA]
I want '_mod_rw_url_' to be equal to QSA but with the substring '/directory/' removed.
I dont want more than one RewriteRule as I understand it creates a new request everytime thus making things more complex, but an extra RewriteCond is ok (its for an app made by a company, so too complex rewriterules will just give me more headache later on)
Thanks in advance for your help.
hi there,
My first post, but have visited this board before when looking for tips and tricks.
Im working with mod_rewrite, trying to remove the string '/directory/' from the [QSA] but since im a newbie all im getting is a huge headache.
so basically in pseudo code:
1. var1=get query string
(var1 is now '/directory/123'
2. var1=var1 with '/directory/' removed
(var1 is now '123'
3. call someurl?param=var1
The line below is what i am trying to modify:
RewriteRule ^(.*) index.php?rewrite=on&_mod_rw_url_=$1 [QSA]
I want '_mod_rw_url_' to be equal to QSA but with the substring '/directory/' removed.
I dont want more than one RewriteRule as I understand it creates a new request everytime thus making things more complex, but an extra RewriteCond is ok (its for an app made by a company, so too complex rewriterules will just give me more headache later on)
Thanks in advance for your help.
Welcome to WebmasterWorld!
It's not completely clear whether you mean that "/directory/" exists in the incoming query string, or if it's part of the requested URL-path. But assuming the latter, you'd just use something like this:
RewriteRule ^directory/(.*)$ /index.php?rewrite=on&_mod_rw_url_=$1 [QSA]
> I want '_mod_rw_url_' to be equal to QSA but with the substring '/directory/' removed.
[QSA] means 'Query String Append,' that is, it instructs mod_rewrite to use the existing query string and add something more to it. The query string is received appended to the requested URL, and should not be confused with the URL, which in this case would be http://www.example.com/directory/<something> with a question mark and the query string following that.
My rule above would make the query string variable _mod_rw_url equal to the requested URL-path, less the leading /directory/, plus the original query string. Is that what you wanted?
> I dont want more than one RewriteRule as I understand it creates a new request everytime thus making things more complex...
No. It only makes a new request if you do an external redirect, and tell the client to re-request the resource using the new URL. Your syntax indicates that you are using an internal rewrite, which won't do that. However, less rules are better, but sometimes a solution requires more than one.
Jim
What you wrote as the solution works perfectly, but unfortunately is not the answer to my problem.
Allow me to explain, Im running an application developed and sold by a company. Their application support search engine friendly URLs by implementing mod_rewrite rules. This is done in a .htaccess file, as many might have hosted their website in a shared environment and therefore not have access to httpd.conf.
Im running a virtual environment and thus have full control of httpd.conf.
Furthermore i have installed their application into /<docroot>/directory instead of /<docroot>/.
They write in their manual, that in order to get mod_rewrite to work i should copy their .htaccess file into the root of the application (/<docroot>/directory), but since i wanted to put the configuration of the .htaccess file into my httpd.conf file I was trying to implement extra rewrite conditions to somehow remove the '/directory' part.
After sleeping on it, i realized im dealing with the problem the incorrectly. After some googling the answer to my prayers was responded (see below).
In short:
If you have a working .htaccess file and you want to copy the content of the file into httpd.conf you should put it into a <directory> tag matching the path of where the .htaccess file was located.
Example:
.htaccess in /www/folder1
would be in httpd.conf:
<Directory /www/folder1>
(copy content of .htaccess in here)
</Directory>
Phew! If anyone find this usefull send me $1 (you never know, i might become a millionaire)
jdmorgan: once again thanks for your answer.