Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
tomturd2 Posted January 30, 2010 Posted January 30, 2010 Currently my forum is in domain.com/forums and i want to remove the /forums off the url. Problem is i don't want to have to move all the files on the server as it will mean my root dir is very messy. I also want to rewrite any old urls to the new path so any old links/indexes still work. Ive tried the following.. RewriteEngine on RewriteRule ^index.php(.*)$ forum/index.php$1 [L] RewriteRule ^forum/(.*)$ /$1 [R,L] But this is causing a redirect loop. Any ideas?
Fishfish0001 Posted January 30, 2010 Posted January 30, 2010 Im not too good, but this might work:RewriteRule ^forums(/)?$ / [R]
atomicknight Posted January 31, 2010 Posted January 31, 2010 It would appear that what you want is something like this:RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) forum/$1 [L] The above allows URLs with or without "forum" to point to the correct files, so old links will work as well as new ones. Of course, you'd need to alter whatever code you're using to generate the visible URLs so that they use the new URL format rather than the old format, but that's beyond the scope of mod_rewrite.
tomturd2 Posted March 27, 2010 Author Posted March 27, 2010 Got it working. RewriteEngine On # Externally redirect to add missing trailing slashes to directory requests RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*[^/])$ http://www.yoururl.com/$1/ [R=301,L] # Map http://www.example.com/ to /forum/ subdirectory RewriteRule ^$ /forum/ [L] # Map http://www.example.com/x to /forum/x unless there is a x in the web root. RewriteCond $1 !^forum/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /forum/$1 [L] # check we're not already internally redirecting and 301 the old links to new location RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^forum/(.*)$ /$1 [R=301,NC,L]
Recommended Posts
Archived
This topic is now archived and is closed to further replies.