| |
| |
|
|
|
|
| |
|
| |
|
| :: |
| Author |
Message |
joey123
Joined: 21 Sep 2007 Posts: 3
|
Posted: Fri Sep 21, 2007 2:20 pm Post subject: mod rewrite not working, can anyone help |
|
|
Hello. I'm new to mod rewrites. I've looked at a ton of tutorials and examples online and can figure out how to set mine up.
Here is how i would like it to work: if the url in the browser is going anywhere but the web root ("www.domain.com" or "www.domain.com/") or any file ending in ".php" or ".html", it will send to "redirector.php", a file that will determine what other files to load.
so anything but the webroot and html and php files will be sent to "redirector.php".
here is what i have. it doesn't work. any ideas on fixing it. also, if there is a better way to get the final results that i'm after, i'm open to suggestions.
RewriteEngine on
Options +FollowSymlinks
RewriteRule ^(.*)!(()|(.php)|(.html))(.*)$ redirector.php?var1=$1?var2=$2&var3=$3&var4=$4 [L]
also, will i need separate rules depending on the number of variables, or can i just have 1 rule assuming that there are 4, if there are less, it will just send black values for the rest (ie "www.domain.com/a/b/c/d" will go to "www.domain.com/redirector.php?var1=a&var2=b&var3=c&var4=d" and "www.domain.com/a" will go to "www.domain.com/redirector.php?var1=a&var2=&var3=&var4=" )
thanks,
joey |
|
|
| Back to top |
|
 |
|
 |
dcz Administrateur - Site Admin

Joined: 28 Apr 2006 Posts: 13354
|
Posted: Mon Sep 24, 2007 10:08 am Post subject: Re: mod rewrite not working, can anyone help |
|
|
And welcome
So, basically, you want to redirect URLs like :
example.com/var1/var2/var3/var4/ to example.com/redirector.php?var1=$1&var2=$2&var3=$3&var4=$4
| Code: | Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteBase ^(.+)/((.+)/)?((.+)/)?((.+)/)?$
RewriteRule ^$ redirector.php?var1=$1?var2=$3&var3=$5&var4=$7 [QSA,L] |
Should do it.
The rewriteconds first check if the file isn't a symlink, a folder or a physical file, then, the RewriteRule handles the four vars to send to the script.
If you know what kind of vars you're expecting, you should restrict the RewriteRule a bit.
| Code: | Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteBase ^([a-z0-9_-]+)/(([a-z0-9_-]+)/)?(([a-z0-9_-]+)/)?(([a-z0-9_-]+)/)?$
RewriteRule ^$ redirector.php?var1=$1?var2=$3&var3=$5&var4=$7 [QSA,L,NC] |
would for example allow a to z chars (A to Z as well), 0 to 9 digits, underscore and hyphen to be used in the variables.
Please note that the redirector.php script should not actually redirect, but rather send the proper output directly.
++ |
_________________ Useful links :
SEO Forum || SEO Directory || SEO phpBB || SEO phpBB3 || Search
____________________
Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Référencement phpBB3 || Recherche |
|
| Back to top |
|
 |
joey123
Joined: 21 Sep 2007 Posts: 3
|
Posted: Tue Sep 25, 2007 5:57 pm Post subject: thanks |
|
|
thanks. that's what i was looking for.
i found an example online that was similar, but it didn't have this line:
RewriteCond %{REQUEST_FILENAME} !-l
but it did have the lines above with the f and the d. what do these do?
also, doing it this way will never produce a 404 error. making search engines think that any url in my domain is valid. is this a bad thing? i was thinking that if i can't get a valid page from the info sent to redirector file that i would keep it from being indexed by search engines (<META NAME="ROBOTS" CONTENT="NOINDEX"> ). does this sound like a good idea?
thanks again for the help |
|
|
| Back to top |
|
 |
dcz Administrateur - Site Admin

Joined: 28 Apr 2006 Posts: 13354
|
Posted: Thu Sep 27, 2007 9:07 am Post subject: Re: mod rewrite not working, can anyone help |
|
|
| dcz wrote: |
The rewriteconds first check if the file isn't a symlink, a folder or a physical file, then, the RewriteRule handles the four vars to send to the script.
|
-l => symlink, -d => directory, -f => file.
About the 404, this rewriterule, together with the rewriteconds, the redirecting only concern the uri like :
some-text/, some/text/, some/text/and/ and some/text/and/more/
As long as they are not physical directories.
So the only thing you should do to perfectly handle the 404 would be to send a 404 header from the redirector.php script, in case the request did not match any existing page.
This won't alter the other 404, like this-is-a-404.html.
++ |
_________________ Useful links :
SEO Forum || SEO Directory || SEO phpBB || SEO phpBB3 || Search
____________________
Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Référencement phpBB3 || Recherche |
|
| Back to top |
|
 |
joey123
Joined: 21 Sep 2007 Posts: 3
|
Posted: Tue Oct 02, 2007 3:21 am Post subject: Re: mod rewrite not working, can anyone help |
|
|
I didn't know you could do that. it makes sense though.
so just add this line as the last else in my test to find what page to load:
header("HTTP/1.0 404 Not Found");
then:
include ("404page.php");
or
include("/template/header.php");
echo "Page Not Found";
include("/template/footer.php");
or something like that
thanks. that's a much better solution. |
|
|
| Back to top |
|
 |
dcz Administrateur - Site Admin

Joined: 28 Apr 2006 Posts: 13354
|
|
| Back to top |
|
 |
|
|
| Navigation |
Similar Topics |
|
|
|
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |