Forum Moderators: phranque

Message Too Old, No Replies

Help needed with my HTaccess file

         

maverick_uk

11:07 am on Nov 8, 2006 (gmt 0)

10+ Year Member



Hey guys, this is my first post, so a quick hello to everybody.

Somebody suggested today that it would be a better idea and more google friendly to re-write urls to nokia-series-60-themes.html rather than nokia/themes1/ for example.

nokia/themes1/ is a page that links to a number of dynamic pages that produce /nokia/n73/themes/ for example, you'll see that in the HTaccess, once I figure out whats wrong, they will also be rewritten to /themes/nokia-n73-themes.html using the dynamic part of the HTaccess.

So here is my setup:

Currently my HTaccess is told to rewrite themes.html to nokia/series60/themes/

I would like it to be rewrititten to themes/series-60-themes.html

However I also need a 301 redirect from nokia/series60/themes to themes/series-60-themes.html but this causes a 500 internal server error on the ENTIRE site not just the pages concerned.

Here is my current HTaccess file:

Options -Indexes +FollowSymLinks

AddType application/x-httpd-php .html

DirectoryIndex newindex.html

RewriteEngine on

RewriteCond %{HTTP_HOST}!^www.mysite.net [NC]
RewriteCond %{HTTP_HOST}!^$
RewriteRule (.*) http://www.mysite.net$1 [R]

redirect 301 /index.html http://www.mysite.net/

RewriteBase /
RewriteRule nokia/themes/ themes1.html
RewriteRule nokia/themes3/ themes3.html
RewriteRule nokia/series-60/news/ news.html

RewriteRule nokia/series-60/themes/ series-60-themes.html

RewriteRule nokia/(.+)/themes/1/ dynamic-themes.php?model=$1 [nc]

RewriteRule nokia/(.+)/themes/3/ dynamic-themes-third.php?model=$1 [nc]

RewriteRule download/(.+)$ /watermarked.php?image=$1 [nc]

I assumed I could simply change the old rewrites to the new ones and then 301 redirect to the new urls. but that doesn't work. hmmm. Any suggestions?

There is a reason I've not just called

maverick_uk

11:51 pm on Nov 8, 2006 (gmt 0)

10+ Year Member



Anybody? I'm getting desperate.

Cheers

Paul

jd01

12:44 am on Nov 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



(Assuming you are using the .htaccess file, not the httpd.conf)
RewriteEngine on

#Mod_Rewrite --- Changed 3 char Neg. pattern to 1 char positive. (Efficiency):
# If the 'HOST' is set. Changed to match a single character in the 'host' string.
RewriteCond %{HTTP_HOST} .

#If the 'HOST' is NOT...
RewriteCond %{HTTP_HOST} !^www.mysite.net [NC]

#Send EVERYTHING to www.example.com if the above two conditions apply.
#Changed to R=301 (Permanent Move) rather than 302 (Undefined).
#Added preceding / to the REDIRECT location.
RewriteRule (.*) http://www.mysite.net/$1 [R=301,L]

#Mod_Alias --- Not sure why it's here.
redirect 301 /index.html http://www.mysite.net/

#Back to Mod_Rewrite
#OK, but not necessarily necessary.
#RewriteBase /

#Rewrite anything that starts with nokia/(variable) to new location...
#Internally? (Rewrite is transparent to the end user --- URL stays the same, information is different --- AKA mapping to a different URL.)
#Added preceding / and L (Last) flag.
RewriteRule nokia/themes/ /themes1.html [L]
RewriteRule nokia/themes3/ /themes3.html [L]
RewriteRule nokia/series-60/news/ /news.html [L]

#Externally? (Redirect is visible to the end user --- URL changes in the browser window.)
#Added/Edited canonical URL, added L (Last) flag, and R=301 (REDIRECT)=(TYPE).
RewriteRule nokia/themes/ http://www.example.com/themes1.html [R=301,L]
RewriteRule nokia/themes3/ http://www.example.com/themes3.html [R=301,L]
RewriteRule nokia/series-60/news/ http://www.example.com/news.html [R=301,L]

I'm not sure I understand exactly what the logic of your file is... I understand what you are trying to do, I know how to do it, but without understanding exactly how you think your file should work, I cannot help you with the thought process to get you where you need to go.

The toughest part of 'helping' someone with an .htaccess file is there are usually a number of different approaches to the same issue, question, implementation. Even if there is a 'semi-standard' 'best application' practice for a given 'ruleset' the end result of the initial implementation can and usually does vary from site to site.

'I need to do this...' is only part of what we need to know to help answer a question. 'I need to do this... I am doing this because... I think this should... What it's really doing is...'

I'm not trying to sound harsh to you, but think people will have an easier time getting answers if they share more detail about what they think should happen with each ruleset, including how it is effected by the previous ruleset.

I know there are times I browse through and don't answer questions, because trying to think through the logic of what someone is doing, why they are doing it, where they are going wrong, advising a fix, and explaining why the fix was necessary takes longer than I have to spend on someone elses questions.

There are times when a short (6 or 8 line post) takes 15 or 20 minutes of 'what if... OR maybe... but if they were really trying to...' before finding the problem, solution, and reasons necessary.

Please, let me know why you are using each set of rules the way you are, with what you think they should do and I'll try to help you through a solution.

Justin

jdMorgan

3:24 am on Nov 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jd01 flagged this mod_alias directive as suspect, and I agree:

redirect 301 /index.html http://www.mysite.net/

If the purpose is to redirect requests for "index.html" to "/", and index.html is defined as the/an index page using a DirectoryIndex directive -- either in .htaccess or in httpd.conf, then these two directives countermanding each other will cause an "infinite loop," and the server and/or client will reach its maximum redirection limit and give up. If the server gives up first, you'll get a 500-Server error.

Jim