Forum Moderators: phranque
i am working on rules of
following
1) FIRST RULE
i want to convert follwoing url
http://domain.com/modules.php?name=News&file=subPage&sid=10
as
http://domain.com/catalog/catalogname10.html
RewriteRule ^/catalog/([a-z])([0-9]*).\html$ /modules.php?name=News&file=subPage$sid=$1
2) SECOND RULE
i want to convert follwoing url
http://domain.com/catalog/default.php?cpath=22_23_27
as
http://domain.com/catalog/subcat22_23_27.html
RewriteRule ^/catalog/([a-z])([0-9]+)_([0-9]+)_([0-9])
.\html$ /catalog/default.php?cpath=$1_$2_$3
3) THIRD RULE
i want to convert follwoing url
http://domain.com/catalog/productinfo.php?cpath=22_23_27&productid=36
as
http://domain.com/catalog22_23_27/product36.html
RewriteRule ^/catalog([0-9]+)_([0-9]+)_([0-9])/product([0-9])\.html /catalog/productinfo.php
cpath=$1_$2_$3&productid=$4
my problem is
1)where can i place these rules at httpd.conf or in .htaccess of directories
2)is it possible to write multiple at a times.
how they are executed.any conflict arises?.
3)how to write RewriteCond condtition for above rules
4)is performance of the request-response decreases by using rewriting rules.
thanks
gi_sreenivas
Welcome to WebmasterWorld [webmasterworld.com]!
1) FIRST RULE
i want to convert follwoing url
[domain.com...]
as
[domain.com...]
RewriteRule ^/catalog/([a-z])([0-9]*).\html$ /modules.php?name=News&file=subPage$sid=$1
(The [NE] flag is used to permit you to use the "$sid" string in the substitution - see cited references below.)
2) SECOND RULE
i want to convert follwoing url
[domain.com...]
as
[domain.com...]
RewriteRule ^/catalog/([a-z])([0-9]+)_([0-9]+)_([0-9]).\html$ /catalog/default.php?cpath=$1_$2_$3
3) THIRD RULE
i want to convert follwoing url
[domain.com...]
as
[domain.com...]
RewriteRule ^/catalog([0-9]+)_([0-9]+)_([0-9])/product([0-9])\.html /catalog/productinfo.php?cpath=$1_$2_$3&productid=$4
my problem is
1)where can i place these rules at httpd.conf or in .htaccess of directories
2)is it possible to write multiple at a times.
how they are executed.any conflict arises?.
You can have as many rules as you like. They are processed first-to-last for each http request.
You must prevent conflicts by specifying patterns that precisely match the URIs you wish to rewrite.
You can use the [L] flag to specify that once the pattern matches and a URI is rewritten, the rewrite engine should stop any further Rule processing for the current http request:
RewriteRule ^/catalog/([a-z]+)([0-9]+)\.html$ /modules.php?name=News&file=subPage$sid=$2 [NE,L]
3)how to write RewriteCond condtition for above rules
This RewriteCond prevents the Rule from being applied if the HTTP_REFERER is your own domain or IP address:
RewriteCond %{HTTP_REFERER} !^(www\.)?mydomain\.com
RewriteCond %{HTTP_REFERER} !^192\.168\.0\.1
RewriteRule ^/catalog/([a-z]+)([0-9]+)\.html$ /modules.php?name=News&file=subPage$sid=$2 [NE]
4) is performance of the request-response decreases by using rewriting rules.
Yes, by a very very tiny amount. mod_rewrite is "built-into" the Apache Server. Therefore, it is much more efficient than any script you might use.
Ref: Introduction to mod_rewrite [webmasterworld.com]
Ref: Apache mod_rewrite documentation [httpd.apache.org]
Jim
there is no problem in rewriting url's in our developemt server.
thanks for your information.
when i tried in our remote server it is not working.
is mod_rewrite work with subdomains?
our remote server setup is like this.
httpd.conf file in /etc/httpd/conf/httpd.conf
web content is in /home/virtual/subdomain.domain.com/var/www/html
i can also see httpd.conf in /home/virtual/subdomain.domain.com/etc/httpd/conf/httpd.conf it seem's it is simply mounted the original httpd.conf
mod_rewrite module is there.i also make AllowOverride to All
i put .htaccess file in /home/virtual/subdomain.domain.com/var/www/html
when i access rewrite url
[subdomain.domain.com...]
of
[subdomain.domain.com...]
i am getting forbidden message.
mod_rewrite requires precision, and therefore, any one of a hundred tiny errors can cause a problem.
You need to use your error log to find out what is wrong.
If insufficient information is present in your error log, you can create a separate log file for mod_rewrite activity, and control the level of logging with the RewriteLog and RewriteLogLevel directives of mod_rewrite [httpd.apache.org].
You might even want to drop back and test a very basic rewrite first:
RewriteEngine on
RewriteRule ^doesnotexist\.html$ /index.html [L]
If it doesn't work, then you have a problem with the way mod_rewrite is installed or configured on your server.
Jim
but not with .htaccess.
i have even test with simple .htaccess file you have given,it is not working.
is it compulsory to have Options +FollowSysmlinks?
what actually FollowSymlinks means?
what other options should i need to have in Options directive?
in server only Options +Includes is there?
Well then it should be easy to find the problem, since a simple rewrite means fewer possible errors.
>is it compulsory to have Options +FollowSysmlinks?
Yes, either in http.conf or in .htaccess. You will usually get a 500-Server Error if you attempt to use mod_rewrite without it.
>what actually FollowSymlinks means?
It has two meanings. The first is the meaning defined in the Options documentation. The second is that it serves as an "enable" for mod_rewrite use in a per-directory .htaccess context.
I want to point out something that you need to know if you are testing in both http.conf and .htaccess. There is a subtle difference in the required pattern of the RewriteRule.
For .htaccess, use:
RewriteEngine on
RewriteRule ^doesnotexist\.html$ /index.html [L]
RewriteEngine on
RewriteRule [b]^/d[/b]oesnotexist\.html$ /index.html [L]
Also, since you have access to the server configuration, you can enable detailed rewrite logging using the RewriteLog and RewriteLogLevel directives. Doing so, and reading the rewritelog after each trial, will make it much easier to find problems.
Since every server setup seems to be slightly different depending on the administrator's goals and choices, there is no way I can give you a magic answer for why you are having trouble. You will have to muddle through this, read the Apache documentation, and experiment until you get it working. Once you have it working, you will find it to be extremely powerful and useful. But the initial stages can be difficult and frustrating so I've tried to help, and I encourage you to keep at it until you succeed.
Jim
Options +FollowSymlinks in .htaccess.It is working now.
thanks Jim for your encouragement and support.
i have some more doubts
1)i have an access to httpd.conf,which is the better way regarding performance to put rewrite rules in httpd.conf or .htaccess.
2)i want to know more about RewriteMap directive.At what situations we can use RewriteMap?
2) RewriteMap is useful for many things. Look to RewriteMap when the function you wish to implement involves long lists of URLs with little in common. If you are familiar with using a "table lookup" in any other programming language, you can think of RewriteMap as an analog to that lookup function.
However, RewriteMap can ONLY be used in httpd.conf, and not in .htaccess.
Jim
i am getting problem in displaying images properly in one of my subdomain's.
RewriteEngine On
RewriteBase /
RewriteRule ^/catalog/StandProducts/$ /modules.php?name=News&file=subPage&sid=55
images are there under images folder in /
modules.php file is processing correclty.
when i have seen RewriteLog file
for images passthrough is taking as /home/virtual/fst4/var/www/html/catalog/
converted rewrite taking as /catakig/StandProducts/images/image1.gif
what is the problem?
is there is any problem in coding?.
it is a php-nuke's code.