开发者

How do I fix old links after modifing .htaccess for Joomla installation in a subfolder?

开发者 https://www.devze.com 2023-02-06 20:48 出处:网络
I have my main Joomla installation in a subdirectory. I used to redirect users from www.my开发者_JAVA百科site.com to www.mysite.com/subdir with a 301 so that the live site was entirely dislocated over

I have my main Joomla installation in a subdirectory. I used to redirect users from www.my开发者_JAVA百科site.com to www.mysite.com/subdir with a 301 so that the live site was entirely dislocated over there.

I don't actually like the fact that all the URL are preceded by the subdirectory /subdir/ (and I also think this is not very good for SEO) so I modified my .htaccess file like this:

RewriteEngine On

RewriteBase / 
# Add trailing slash if path does not contain a period or end with a slash
RewriteCond %{REQUEST_URI} !(\.|/$) 
RewriteRule (.*) http://www.mysite.com/$1/ [R=301,L] 

#Change http://yoursite.com to http://www.mysite.com (Optional) 
RewriteCond %{HTTP_HOST} ^mysite.com$ 
RewriteRule ^/?(.*)$ http://www.mysite.com/$1 [R=301,L]

#Rewrites http://www.mysite.com/subdir to http://www.mysite.com/
RewriteRule ^(.*)$ subdir/$1 [L]

I also edited the configuration file for Joomla! so that now all the links in the site point (correctly) to www.main.com/theirquery and noto to www.main.com/subdir/theirquery

Now, however, all the old links (that have been posted to other webistes, for example) appears to be broken (404): how can I solve this? I think I have to redirect (301) them to the new subdirectory-free address, that will be (another time) silently redirected with the htaccess I posted. But I don't know how to do this!

Thank you in advance!


Can you try setting the $live_site parameter in configuration.php? You need to edit it directly rather than through the backend of Joomla.


You need to add this to your htaccess.

RewriteRule ^subdir/(.*)$ /$1 [R=301,NC,L]


This is not possible since the old links where not physical but stored in a database, so redirecting them wouldn't be possible without passing through the database again.

0

精彩评论

暂无评论...
验证码 换一张
取 消