Forum Moderators: phranque
I'm trying to redirect a specific url. If I find a php variable like : ' c=CourseNumber', i want to redirect the url.
Example :
If i have something like :
"http://localhost/boards/index.php?c=1&sid=589aa6606d4de2d6a45fc612363a5a7c"
c=1, I want to redirect to algebra course, so I want to redirect to:
"http://localhost/algebra/forums/"
I have tried RedirectMatch, but it doesn't work. The caracter '?' make the request not work.
"RedirectMatch ^(.*)c=1(.*) [localhost...]
Now I'm trying RewriteCond and RewriteRule :
"RewriteCond %{REQUEST_URI} ^(.*)c=1(.*)
RewriteRule ^/$ /algebra/forums/"
The problem with RewriteCond is that I have never succeed a request, even a simple one.
Simple example :
The url is : [localhost...]
I just want to make something happen if we have 'info.php' in the REQUEST_URI
"Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^info\.php
RewriteRule ^/$ /index.php"
Thank you for your help.
Welcome to WebmasterWorld.
Looks like you were close =)
RewriteCond %{REQUEST_URI} ^(.*)c=1(.*)
RewriteRule ^/$ /algebra/forums/
This should get you there:
The .htaccess version is:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^c=([0-9]+)
RewriteRule ^(index\.php)?$ /algebra/forums/ [L]
RewriteRule ^info\.php$ /index.php [L]
And in the Conf file:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^c=([0-9]+)
RewriteRule ^/(index\.php)?$ algebra/forums/ [L]
RewriteRule ^/info\.php$ index.php [L]
The difference in the two is the / is stripped in the .htaccess prior to any comparrison, where it is present in the httpd.conf file.
() = grouping
? = 0 or 1 of the preceding characters or group of characters
So, (string)? makes a string optional
\ = escaping character
.(dot) = meta character
\. = matches a litteral dot, not the meta meaning of 'any character except the end of a line'
L = Last - should always be used, unless you *know* you do not need it. If not each new, rewritten URI will be compared to all other rules and possibly rewritten again to a different location - can have some odd results, unless you know how to use it.
Options +FollowSymLinks - is only necessary if not alread defined in the httpd.conf file, so in some case is necessary and in others is not - if you have trouble try with and without.
AllowOverride FileInfo - Same as Options. If you have trouble, try with and without each and both together.
Hope this helps.
Justin