简体   繁体   English

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

[英]URL Rewrite not working on localhost in ubuntu

So i'm running lampp on ubuntu 11.10 and i have the following problem 所以我在ubuntu 11.10上运行灯泡,我有以下问题

i need this url: localhost/myname/oefeningenPHP/cms/index.php?head=about 我需要这个网址:localhost / myname / oefeningenPHP / cms / index.php?head = about

rewritten to: localhost/myname/oefeningenPHP/cms/about 改写为:localhost / myname / oefeningenPHP / cms / about

The url is kinda messy because i have lots of folder with different PHP exercises for school. 网址有点乱,因为我有很多不同的PHP练习文件夹。

My .htacces is located in: localhost/myname/oefeningenPHP/cms 我的.htacces位于:localhost / myname / oefeningenPHP / cms

since cms is my sites root. 因为cms是我的网站root。

.htacces contains the following code: .htacces包含以下代码:

<IfModule mod_rewrite.c>

Options +FollowSymLinks
RewriteEngine on

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

</IfModule>

But returns a 404 error. 但是返回404错误。

Furthermore i'm sure the rewrite module is being loaded since it's uncommented in the http.conf file 此外,我确定正在加载重写模块,因为它在http.conf文件中没有注释

I've ran out of ideas so i'm hoping someone here can help me. 我已经没想完了所以我希望有人可以帮助我。 I'm not very sure about the forward slashes in the RewriteRule, but i've tried various things and nothing works 我不太确定RewriteRule中的正斜杠,但我尝试了各种各样的东西,没有任何作用

If you have already run sudo a2enmod rewrite command but your URL Rewrite is not working. 如果您已经运行了sudo a2enmod rewrite命令,但您的URL Rewrite不起作用。
To make .htaccess files work as expected, you need to edit this file: 要使.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

try 尝试

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

You should also see if you .htaccess is enabled by adding some junk to it eg asdfasdfasdfasd , save it and try to access the URL. 您还应该看看是否通过向它添加一些垃圾来启用.htaccess,例如asdfasdfasdfasd ,保存并尝试访问URL。 If you do not get a 500 error, then it is not enabled. 如果没有收到500错误,则表示未启用。

To enable it look for a line that says 要启用它,请查找说明的行

AllowOverride None

and change it to 并将其更改为

AllowOverride All

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM