Codeigniter.htaccess

发布于 2024-10-28 15:15:19 字数 1016 浏览 1 评论 0原文

抱歉我的英语不好...

我有最基本的 CodeIgniter 设置,但无法使其工作...如果我访问该网址 http://domain.com/index.php?controllerX/method 它工作正常。

现在我希望能够访问 http://domain.com/method

我在routes.php“controllerX”上配置为默认控制器并尝试使用以下 .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]

我尝试了多个 .htaccess,每次服务器都返回 403 错误。即使我的 .htaccess 仅包含第一行“RewriteEngine on”,它也会显示 403 错误。我尝试将每个文件夹设置为 chmod 777 或 755 进行测试,但这没有任何改变。

有没有办法查看哪些资源给出了 403 错误?或者我在其他地方犯了错误?

好吧,我在某处读到我需要在 htaccess 上使用“Options +FollowSymLink”...服务器向我显示 500 个错误:(

编辑 好的,现在可以使用以下 htaccess:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]

Sorry for my bad english...

I have the most basic possible CodeIgniter setup and can't make it work... if i access the url
http://domain.com/index.php?controllerX/method it works fine.

Now I want to be able to access
http://domain.com/method

I configured on routes.php "controllerX" to be the default controller and try to use the follow .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]

I have tried multiple .htaccess and everytime the server just returns 403 errors. Even if my .htaccess contains only the first line "RewriteEngine on", it shows 403 errors. I have tried to set every folder to chmod 777 or 755 to test and this change nothing.

Is there a way to see what resource are giving the 403 error? Or am I comiting a mistake elsewhere?

Ok, i readed somewhere that I need "Options +FollowSymLink" on my htaccess ... with that the server show me 500 errors :(

EDIT
Ok, now its working, with the follow htaccess:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹泡泡o 2024-11-04 15:15:19

将您的 .htaccess 文件更改为:

除了我们在 .htaccess 文件中所做的更改之外,我们还必须验证/更改以下设置:

Apache 读取位于 /var/www/html 目录下的 .htaccess 文件。
您可以通过编辑httpd.conf文件来做到这一点:

sudo nano /etc/httpd/conf/httpd.conf

找到该部分并将AllowOverride None更改为

AllowOverride All

 <Directory /var/www/html>
    AllowOverride All
 </Directory>
Save and exit.

现在重新启动Apache以使更改生效:

sudo systemctl restart httpd

rest 这对我有用

change your .htaccess file as:

apart from the changes we did in .htaccess file we also have to verify/changed the following setting :

Apache to read .htaccess files located under the /var/www/html directory.
You can do this by editing httpd.conf file:

sudo nano /etc/httpd/conf/httpd.conf

Find the section and change AllowOverride None to

AllowOverride All

 <Directory /var/www/html>
    AllowOverride All
 </Directory>
Save and exit.

Now restart Apache to put the change into effect:

sudo systemctl restart httpd

rest this worked for me

自由如风 2024-11-04 15:15:19

我认为您的问题也已在此处得到解答

RewriteEngine On
RewriteBase /

# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

# Enforce www
# If you have subdomains, you can add them to 
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.plugb.com/$1 [L,R=301]


RewriteBase /    
RewriteCond %{HTTP_HOST} !=""
RewriteRule ^index.php(/.*)?$ http://%{HTTP_HOST}$1 [R=301]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

I think your question is also answered here

RewriteEngine On
RewriteBase /

# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

# Enforce www
# If you have subdomains, you can add them to 
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.plugb.com/$1 [L,R=301]


RewriteBase /    
RewriteCond %{HTTP_HOST} !=""
RewriteRule ^index.php(/.*)?$ http://%{HTTP_HOST}$1 [R=301]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文