Forum Moderators: phranque
I am have problems redirecting with htaccess. Im sure this will be easy for some here, however Its been killing me for hours now.
Here's the rule:
RewriteRule ^demo/(.*)$ /auxdir/models/$1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /auxdir/models/(.*)$\ HTTP/
RewriteRule ^auxdir/models/(.*)$ http://www.example.com/demo/%1 [R=301,L]
RewriteRule ^demo/(.*)$ /auxdir/models/$1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /auxdir/models/\ HTTP/
RewriteRule ^auxdir/models/ http://www.example.com/demo/? [R=301,L]
The code I am using doesnt seem to work.
very frustrating.
Thanks in advance!
[edited by: jdMorgan at 1:04 pm (utc) on Sep. 5, 2009]
[edit reason] example.com [/edit]
So...
Do you have any working rewriterule redirects in this .htaccess file?
Will something simple like the following rule work?
RewriteRule ^foo\.html$ http://www.WebmasterWorld.com/ [R=302,L]
When posting here, please understand that "it doesn't work" is not a very useful statement. For best results, we need to know:
What URL did you type?
What did you expect to happen?
What in fact did happen?
How did the actual results differ from your expectations?
Are there any relevant entries in your server error log?
Did you delete your browser cache before testing?
Jim
The root http directories htaccess file is quite extensive. I utilize htaccess lots (so could be something conflicting)
htaccess works great thus far. I have directory "models" that sits in "auxdir" directory. The "auxdir" directory sits in root http directory. (/www/auxdir/models/) I want to rename the directory "models" to "demo" and eliminate "audir". would be "/www/demo/" after htaccess or "example.com/demo/". The folder "demo" (really '/auxdir/model/') has lots of php files and directories all corresponding to an index.php file "example.com/demo/index.php?uid_pid=weeee-etc-etc".
The Rule:
RewriteRule ^demo/(.*)$ /auxdir/models/$1 "example.com/demo/index.php?etc-etc"...
but will not redirect when the real path is requested.
"example.com/auxdir/models/index.php?etc-etc"
i have been trying to get a redirect in htaccess to work for this auxdir/models directory I have done it this way for many other directories, yet have troubles with only this one. I realize my rules may not be specific enough. I need to have more specific rules for this one directory.
Then, in the substitution URL, you *can* back-reference the RewriteRule's pattern match instead of the RewriteCond's pattern-match to simplify query-string handling (the query will pass through unchanged by default). I show both methods below, with differences highlighted.
So, the rules should look like this:
# Externally redirect (only) direct client requests for /auxdir/models/ URLs to /demo/ URLs
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /auxdir/models/[b][^\ ]*[/b]\ HTTP/
RewriteRule ^auxdir/models[b]/(.*)$[/b] http://www.example.com/demo[b]/$1[/b] [R=301,L]
#
# Internally rewrite /demo/ URL requests to /auxdir/models/ directory
RewriteRule ^demo/(.*)$ /auxdir/models/$1 [L]
# Externally redirect (only) direct client requests for /auxdir/models/ URLs to /demo/ URLs
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /auxdir/models/[b]([^\ ]*)[/b]\ HTTP/
RewriteRule ^auxdir/model[b]s/[/b] http://www.example.com/demo[b]/%1[/b] [R=301,L]
#
# Internally rewrite /demo/ URL requests to /auxdir/models/ directory
RewriteRule ^demo/(.*)$ /auxdir/models/$1 [L]
Jim
[edited by: jdMorgan at 2:51 pm (utc) on Sep. 5, 2009]
(thank you)
Cleaned cache on 2 separate pcs, still will not redirect for some strange reason. I wrote some php code to try to accomplish this as well, using an if statement. I basically told php to look out for "auxdir/models/" in the requested URL, and when true to redirect... for some strange reason this triggered an infinite loop, even when "auxdir/models/" was not in the URL. (requesting just '/demo/') <--see no "auxdir/models/" (yet still looped in php)
(T.Y. fyh)
includes:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /auxdir/models/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /demo/index.php [L]
</IfModule>
Although my application does not function correctly without this htaccess file, I temporarily removed it to see if it would then redirect, and a saw no difference.
Thanks again for your time and help.
Things to check: