簡體   English   中英

URL重寫不在ubuntu中的localhost上工作

[英]URL Rewrite not working on localhost in ubuntu

所以我在ubuntu 11.10上運行燈泡,我有以下問題

我需要這個網址:localhost / myname / oefeningenPHP / cms / index.php?head = about

改寫為:localhost / myname / oefeningenPHP / cms / about

網址有點亂,因為我有很多不同的PHP練習文件夾。

我的.htacces位於:localhost / myname / oefeningenPHP / cms

因為cms是我的網站root。

.htacces包含以下代碼:

<IfModule mod_rewrite.c>

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^/([a-z]+) /index.php?head=$1 

</IfModule>

但是返回404錯誤。

此外,我確定正在加載重寫模塊,因為它在http.conf文件中沒有注釋

我已經沒想完了所以我希望有人可以幫助我。 我不太確定RewriteRule中的正斜杠,但我嘗試了各種各樣的東西,沒有任何作用

如果您已經運行了sudo a2enmod rewrite命令,但您的URL Rewrite不起作用。
要使.htaccess文件按預期工作,您需要編輯此文件:

Step1 : sudo vi /etc/apache2/sites-available/default

Step2 : Look for a section that looks like this: 
    <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
                # Uncomment this directive is you want to see apache2's
                # default start page (in /apache2-default) when you go to /
                #RedirectMatch ^/$ /apache2-default/
        </Directory>
You need to modify the line containing AllowOverride None to read AllowOverride All.
step 3 : sudo /etc/init.d/apache2 reload

嘗試

RewriteRule ^([a-z]+) index.php?head=$1 [L]

您還應該看看是否通過向它添加一些垃圾來啟用.htaccess,例如asdfasdfasdfasd ,保存並嘗試訪問URL。 如果沒有收到500錯誤,則表示未啟用。

要啟用它,請查找說明的行

AllowOverride None

並將其更改為

AllowOverride All

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM