Forum Moderators: phranque
I only wanted it to do the homepage not any folder or sub folder of the homepage, is there anyone who can help me solve this as my htaccess is complicated, here it is, if i can fix this then some of these rules i won't need:
Redirect permanent /portfolio /designs/index.php
Redirect permanent /portfolio/ /designs/index.php
RewriteRule ^designs/([^/\.]+)/?$ designs/project.php?name=$1 [L]
RewriteRule ^pages/([^/\.]+)/?$ includes/page.php?name=$1 [L]
RewriteRule ^netmag/ includes/page.php?name=netmag [L]
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,QSA,L]
Directoryindex %{HTTP_HOST} includes/page.php?name=homepage
RewriteRule ^designs/([0-9][0-9])/$ designs/index.php?page=$1
the last one doesn't seem to work either which is also annoying :( sorry been at this along time with no avail.
[edited by: eelixduppy at 5:52 pm (utc) on Nov. 16, 2008]
[edit reason] exemplified [/edit]
Don't mix directives from Mod_Alias (Redirect) with those from Mod_Rewrite (RewriteRule) as you cannot guarantee the order they are processed in. Use RewriteRule for all of the rules.
I wouldn't redirect to a URL containing "index.html" I would redirect to the folder name terminated with a slash.
I would also redirect requests for "index.html" such that the filename is removed.
Finally, your redirect to fix non-www requests to be www URLs should be placed after all other redirects, and before all of your rewrites. Failure to do so leads either to a redirection chain or to internal path names from the rewrite being exposed back out to the viewer.
Make sure that all of your rewrites are terminated with [L]. One hasn't got that.
Fix that lot up, and post again, and we'll take it from there.
Redirect permanent /portfolio /designs/
Redirect permanent /portfolio/ /designs/
RewriteRule ^designs/([^/\.]+)/?$ designs/project.php?name=$1 [L]
RewriteRule ^pages/([^/\.]+)/?$ index.php?name=$1 [L]
RewriteRule ^netmag/ includes/page.php?name=netmag [L]
Directoryindex %{HTTP_HOST} index.php?name=homepage [L]
RewriteRule ^designs/([0-9][0-9])/$ designs/index.php?page=$1 [L]
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,QSA,L]
I am new to htaccess so the other stuff you said went straight over my head, sorry :(
The RewriteRule ^designs/([0-9][0-9])/$ designs/index.php?page=$1 [L] should change this: /designs/index.php?page=2 to designs/2/ but doesn't seem to work, any help would be appreciated.
Your two rules using Redirect Permanent MUST be recoded to use RewriteRule.
DirectoryIndex should not have [L] on the end.
Without these fixes you will get random and unexplained behaviours for some types of request.
Rewrites cannot "change" URLs. They merely take external URLs requests and fetch the content from an alternative location from within the server. If you want to "change" URLs you need to link to the URL you want people to see from within the pages of your site.
This stuff is unforgiving of coding errors, and you can take your entire site offline or block all search engines from indexing it in some very easy to make errors.
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,QSA,L]
RewriteRule ^portfolio designs/ [L]
RewriteRule ^portfolio/ designs/ [L]
RewriteRule ^designs/([^/\.]+)/?$ designs/project.php?name=$1 [L]
RewriteRule ^pages/([^/\.]+)/?$ index.php?name=$1 [L]
RewriteRule ^netmag/ includes/page.php?name=netmag [L]
Directoryindex %{HTTP_HOST} index.php?name=homepage [L]
RewriteRule ^designs/([0-9][0-9])/$ designs/index.php?page=$1 [L]
The remaining issue is i want to fetch the data used here: [domain.com...] to be a seo friendly url like [domain.com...]
Organize your rules redirects first, in order from most-specific pattern to least-specific, followed by internal rewrites, again in order from most-specific to least-specific.
Also, you need to go look at the Apache mod_dir documentation, because your syntax for DirectoryIndex is badly wrong -- You appear to be trying to use it as if it were a RewriteCond, and mod_dir won't accept two arguments.
Jim
redirect the content from index.php?name=homepage to the root and only the root so yourdomain.com and not any subfolder it doesn't work, it won't show the content from the db.
i tried the redirectrule before i posted the message but it never worked as far as the designs page is concerned again its the subfolder thing.
I want when a user types in portfolio with / or without / they get taken to designs/
but when they type in designs/2/ the content comes from designs/index.php?page=2
# Declare default index page to be anything but index.php
DirectoryIndex /index.html
#
# Redirect direct client requests (only) for index.php to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
#
# Redirect /portfolio requests to /designs/
RewriteRule ^portfolio/?$ http://www.example.com/designs/ [R=301,L]
#
# Redirect non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} !^www.\example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# Rewrite root index page requests to index.php?name=homepage
RewriteRule ^$ /index.php?name=homepage [L]
#
# Rewrite /designs/<numbers>/ to /index.php?page=<numbers>
RewriteRule ^designs/([0-9]+)/$ /designs/index.php?page=$1 [L]
#
# Rewrite /designs/<any no-file-extension path in designs dir>/ to /project.php?name=<any no-file-extension path in designs dir>
RewriteRule ^designs/([^/.]+)/?$ /designs/project.php?name=$1 [L]
#
# Rewrite ^pages/<any no-file-extension path in pages dir> to /index.php?name=<any no-file-extension path in pages dir>
RewriteRule ^pages/([^/.]+)/?$ /index.php?name=$1 [L]
#
# Rewrite /netmag/<anything at all or nothing> to /includes/page.php?name=netmag
RewriteRule ^netmag/ /includes/page.php?name=netmag [L]
Jim