You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

需删除htaccess中page.php?url=参数,URL重写遇403禁止访问问题

Hey there, let’s work through that 403 Forbidden error you’re getting when trying to clean up your news portal’s URLs. I’ve troubleshooted plenty of Apache rewrite issues like this, so here’s a step-by-step fix to get your pretty URLs working:

1. Verify Apache’s Rewrite Module is Enabled

First up, make sure the mod_rewrite module is turned on—this is required for URL rewriting to work at all:

  • For Linux/Apache environments, run these commands in your terminal:
    sudo a2enmod rewrite
    sudo systemctl restart apache2
    
  • If you’re using XAMPP/WAMP on Windows, open your httpd.conf file, find the line #LoadModule rewrite_module modules/mod_rewrite.so, remove the leading #, then restart your Apache server.
2. Fix Your .htaccess Rewrite Rules

In your project_07_news_portal directory, create or update the .htaccess file with these rules. This will map your clean URLs to the original page?url=... structure:

RewriteEngine On

# Don't rewrite actual files or directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Forward clean URLs to your page handler (adjust to page.php if needed)
RewriteRule ^(.*)$ page?url=$1 [L,QSA]

Pro tip: If your handler file is named page.php (not just page), make sure to include the .php suffix in the rule—missing this is a common cause of 403 errors.

3. Allow .htaccess Overrides in Apache’s Config

Apache blocks .htaccess changes by default for security. You’ll need to update your site’s Apache configuration (like 000-default.conf or your custom virtual host file) to allow overrides in your project directory:

<Directory /var/www/html/project_07_news_portal>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>

After making this change, restart Apache again—this is the #1 reason people hit 403s with rewrite rules.

4. Check File & Directory Permissions

Incorrect permissions can trigger Apache’s security restrictions:

  • Set your .htaccess file to 644 (owner read/write, others read-only):
    chmod 644 /var/www/html/project_07_news_portal/.htaccess
    
  • Set your project directory to 755:
    chmod 755 /var/www/html/project_07_news_portal
    

Avoid using 777 permissions—Apache will reject these as insecure, leading to a 403.

5. Test & Debug

Once everything’s configured, visit project_07_news_portal/altay_tanki_ihalesi_icin_geri_sayim and check if your PHP code can access $_GET['url'] correctly. If you still get errors, check Apache’s error log (usually /var/log/apache2/error.log on Linux) for specific details—it’ll tell you exactly whether the issue is with your rewrite rules, permissions, or something else.

内容的提问来源于stack exchange,提问作者John F.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:15:30