本地ourallnews站点index类URL重定向异常跳转至dashboard的修复方法
Fix for Index URL Redirects Landing on localhost/dashboard Instead of ourallnews Root
Got it, let's troubleshoot why your index URL redirects are sending you to localhost/dashboard/ instead of your ourallnews site root. The issue boils down to how you've specified the target path in your first RewriteRule.
The Root Cause
You set RewriteBase /ourallnews/, but when you use an absolute path starting with / (like / $1) in the RewriteRule target, it completely bypasses the RewriteBase and points straight to your server's root directory (localhost/). Since your server’s default root likely serves the dashboard when accessing the bare domain, that’s where you’re being redirected.
Corrected .htaccess Configuration
Here’s the fixed code with explanations for the change:
RewriteEngine on RewriteBase /ourallnews/ # Fixed: Redirect index pages to ourallnews root (uses relative path) RewriteRule ^(.*)index\.(php|html?)$ $1 [R=301,NC,L] # Existing category redirect rule (unchanged) RewriteCond %{THE_REQUEST} /category(?:\.php)?\?cat=([^\s&]+) [NC] RewriteRule ^ %1? [R=301,L] # Internal rewrite for pretty URLs (unchanged) RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([\w-]+)$ category.php?cat=$1 [L,QSA]
What Changed?
- Replaced
/ $1with$1: Using a relative path respects theRewriteBase /ourallnews/setting. Now, when you visitlocalhost/ourallnews/index.php, it redirects correctly tolocalhost/ourallnews/instead of the server root. - Alternative Absolute Path Option: If you prefer explicit absolute paths for clarity, you can write the rule like this instead:
RewriteRule ^(.*)index\.(php|html?)$ /ourallnews/$1 [R=301,NC,L]
Quick Checks to Ensure It Works
- Confirm
mod_rewriteis enabled on your Apache server. - Make sure the
.htaccessfile is placed directly inside yourourallnewsdirectory (not the server’s root folder). - Clear your browser cache before testing—301 redirects are cached aggressively, so old rules might still be in effect otherwise.
内容的提问来源于stack exchange,提问作者Dipak
相关产品推荐
相关产品推荐

