.htaccess 代码点火器

bqujaahr  于 2022-11-16  发布在  其他
关注(0)|答案(2)|浏览(157)

抱歉我的英语不好...
我有最基本的可能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错误?或者我在其他地方犯了错误?
好吧,我读到的地方,我需要“选项+跟随symlink”对我的htaccess ...与服务器显示我500错误:(

EDIT好的,现在可以工作了,使用以下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]
lx0bsm1f

lx0bsm1f1#

将.htaccess文件更改为:
除了我们在.htaccess文件中所做的更改外,我们还必须验证/更改以下设置:
Apache读取位于/var/www/html目录下的.htaccess文件。您可以通过编辑httpd.conf文件来执行此操作:
/etc/文件名:/etc/文件名:
找到该部分并将AllowOverride None更改为

AllowOverride All

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

现在重新启动Apache以使更改生效:
sudo systemctl重新启动httpd
其余的对我很有效

yv5phkfx

yv5phkfx2#

我想你的问题也得到了回答

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]

相关问题