Redirect all traffic to index.php using mod_rewrite

前端 未结 5 1151
Happy的楠姐
Happy的楠姐 2020-11-28 14:29

I\'m trying to build a url shortener, and I want to be able to take any characters immediately after the domain and have them passed as a variable url. So for example

相关标签:
5条回答
  • 2020-11-28 15:09

    Try it without using using RewriteCond.

    0 讨论(0)
  • 2020-11-28 15:09

    Check under Apache modules and make sure that rewrite-module is enabled. I had a similar issue and it was resolved by enabling the rewrite-module.

    0 讨论(0)
  • 2020-11-28 15:17

    To rewrite all requests to /index.php ,you can use :

    RewriteEngine on
    
    
    RewriteCond %{REQUEST_URI} !^/index.php$
    RewriteRule ^(.+)$ /index.php?url=$1 [NC,L]
    

    The RewriteCondition RewriteCond %{REQUEST_URI} !^/index.php$ is important as it excludes the rewrite destination we are rewriting to and prevents infinite looping error.

    0 讨论(0)
  • 2020-11-28 15:18

    ByTheWay don't forget to enable mod rewrite,in apache on ubuntu

    sudo a2enmod rewrite 
    

    and then restart apache2

    sudo /etc/init.d/apache2 restart
    

    edit: it is an old question that helped me but I lost hours testing my apache2.conf file on one side and .htaccess file on the other side and still no light.

    0 讨论(0)
  • 2020-11-28 15:27

    Try replacing ^(.*) with ^(.*)$

    RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
    

    Edit: Try replacing index.php with /index.php

    RewriteRule ^(.*)$ /index.php?url=$1 [L,QSA]
    
    0 讨论(0)
提交回复
热议问题