htaccess rewrite rule not working with magento - .htaccess

This is the rewrite rule does not working in .htaccess:
RewriteCond %{REQUEST_URI} ^/magento/resultados-busqueda/
RewriteRule resultados-busqueda/(.*) /magento/index.php/catalogsearch/result/$1 [L,QSA,NC]
If I add [R] flag, it's work fine, but without [R] does not work.
Please help!!
Sorry for my english.
Thank you!

It turns out that the new Apache version has changed in some way, if you are using apache 2.4, I suggest you to change your etc/apache2/apache2.conf file (you'll need root permission) as follows:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Then restart apache.
sudo service apache2 restart
It works ;)

Use below .htaccess snippet in your $DOCUMENT_ROOT/magento/.htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /magento
RewriteRule ^resultados-busqueda/([^/]+)/?$ /magento/index.php/catalogsearch/result/?q=$1 [QSA,P,NC]

URI domain/magento/resultados-busqueda/pantalones and show error 404.
This my .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /magento
RewriteRule ^api/rest api.php?type=rest [QSA,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^resultados-busqueda/(.*)$ /magento/index.php/catalogsearch/result/?q=$1 [L,NC]
RewriteRule .* index.php [L]

Related

Codeigniter V4 not loading public resources

I am using CodeIgniter 4.1.3.
below is my .htaccess
#Options All -Indexes
<IfModule mod_rewrite.c>
#Options +FollowSymlinks
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
ServerSignature Off
options all and followSymlinks not supported on server.
Working fine on localserver
Front page is loaded but it is not loading css,javascript and image from public directory giving 404 error.
not sure what need to be change.
With your shown samples, please try following htaccess Rules file. Make sure to place this in your root directory. Also make sure to clear your browser cache before testing your URLs.
Options -Multiviews
<IfModule mod_rewrite.c>
#Options +FollowSymlinks
RewriteEngine On
RewriteBase /public/
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php/$1 [L,NC,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
ServerSignature Off
JS/CS rewrite/redirect: You may need to use base tag to fix your js and other relative resources. If you are linking js files using a relative path then the file will obviously get a 404 because its looking for URL path. for example if the URL path is /file/ instead of file.html then your relative resources are loading from /file/ which is not a directory but rewritten html file. To fix this make your links absolute or use base tag. In the header of your webpage add this <base href="/"> so that your relative links can load from the correct location.
Options All -Indexes
Options +FollowSymlinks
works well on apache but if your server is centos then use this
Options -Indexes
Options +SymLinksIfOwnerMatch

Htaccess redirect to controller action don't work properly

I want to redirect to my contoller - SiteController.php and action actionLanguage. I think my htaccess is OK but can't reach the action. Everything that I am trying to put in the url leads me to admin/site/index and not to admin/site/language in my particular case. My .htaccess :
# prevent directory listings
Options -Indexes
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/admin/gii/?$
RewriteRule . backend/web/index.php?r=gii [L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT]
RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /frontend/web/$1
This line RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT] must execute to backend/web/site/language when I type www.website.com/admin/site/languageright ? Or I am in some mistake? It redirects the request to the admin/site/index now. Appreciate every advice! Thank you in advance!
EDIT:
Backend .htaccess:
AddDefaultCharset utf-8
Options FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
RewriteRule ^static - [L]

Yii2 + htaccess + wamp gives 404 Not Found

Please help, I've read a lot of posts about this issue, nothing helps.
I have yii2 installation under: c:/sites/mysite
The index.php file is in: c:/sites/mysite/web
I have htaccess file under c:/sites/mysite that looks like this:
# turn on rewrite engine
RewriteEngine on
RewriteBase /
RewriteRule ^index.html?$ home.php [NC,R,L]
DirectoryIndex home.php
# on what should it skip the rules
RewriteRule ^(favicon.ico) - [L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Do not allow calls from servers testing ou server fi were a proxy
# http://serverfault.com/questions/499125/banning-all-azenv-php-request-to-my-server
#RewriteCond %{HTTP_REFERER} .*/azenv\.php [NC,OR]
#RewriteRule .* - [F]
#RewriteCond %{HTTP:X-Forwarded-Proto} !https
#RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
# otherwise forward it to index.php
RewriteRule . index.php
I have my-vhosts file that has this code:
ServerName armanager
ServerAlias armanager
DocumentRoot "c:/sites/armanager/web"
Options Indexes FollowSymLinks
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
Going to mysite on firefox works fine.
I have a controller esController with actionSettings function.
I have a view settings.php
Going to mysite/es/settings gives me the dreaded 404 Not Found error.
Can you please help?
Ok, I added this .htaccess in the web folder:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</IfModule>
Now, everything works.

rewrite rule for shop in lithium / apache

I have a lithium installation and all the .htaccess works fine.
I need to install OpenCart as a shopping cart in app/webroot/shop
I copied all the files and also changed the .htaccess file in the root folder of lithium installation as
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule shop/(.*) /app/webroot/shop/$1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Still when I browse http://domain.com/shop it takes me to http://domain.com/app/webroot/shop/
With an error on page:
Exception
lithium\action\DispatchException (code 404)
Action `webroot` not found.
Please help me in solving this problem.
You may try this instead:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/app/webroot/shop/? [NC]
RewriteRule ^shop/(.*) /app/webroot/shop/$1 [L,NC]
RewriteCond %{REQUEST_URI} !/app/webroot/? [NC]
RewriteRule ^$ /app/webroot/ [L,NC]
RewriteCond %{REQUEST_URI} !/app/webroot/? [NC]
RewriteRule ^(.*) /app/webroot/$1 [L,NC]
</IfModule>
The problem is that your last "catch all" rule is also redirecting all requests for the shop to lithium, which you don't want.
Try this
Options +FollowSymlinks -MultiViews
RewriteEngine On
# Rewrite all URLs that start with /shop to /app/webroot/shop
RewriteRule ^shop/.? /app/webroot/shop%{REQUEST_URI} [L]
# Rewrite all URLs that don't start with /app/webroot/shop to /app/webroot
RewriteCond %{REQUEST_URI} !^/app/webroot/shop
RewriteRule .? /app/webroot%{REQUEST_URI} [L]

mod rewrite .htaccess URL redirect

I want to simply point the www.mysite.com/corporate to www.mysite.com/services/corporate
here is my .htaccess:
#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#Options -Indexes
#ErrorDocument 403 default
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^corporate$ services/corporate
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*) index.php
RewriteCond %{HTTP:Authorization} !^$
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>
#php_value register_globals 0
Use mod_rewrite. Place something like this in .htaccess in the root directory:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)/corporate/(.*)$ $1/services/corporate/$2 [R,L]
See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html for more info.
Difficult to understand some parts of your .htaccess code but you can add one more line before </IfModule> there:
RewriteRule ^corporate/?$ services/corporate [NC,L,R=301]

Resources