rewrite rule for shop in lithium / apache - .htaccess

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]

Related

Need help writing htaccess rule

Currently my localhost URL is like localhost/apnaujjain/page.php?page_id=1&action=contacts
Now I want to write a rule so that when I go to above url it just rewrite the url like localhost/apnaujjain/contacts.html
See it should convert .php into .html without affect page content.
Until now I've tried
Options +FollowSymLinks -MultiViews
RewriteEngine on
#RewriteBase /
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.php?page_id=1$&action=2$
RewriteRule ^(.*)\.php $2.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]
But it's not working.
You can use this code in /apnaujjain/.htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /apnaujjain/
# redirect localhost/apnaujjain/page.php?page_id=1&action=contacts to
# localhost/apnaujjain/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&action=([^\s&]+) [NC]
RewriteRule . %1/%2.html? [R=301,L]
RewriteRule ^([^/]+)/([^.]+)\.html$ page.php?page_id=$1&action=$2 [NC,L,QSA]

Hide the directory in url using .htaccess

I've the links as follow:
localhost/a/site/watch/contact/
localhost/a/site/details/about/
where .htaccess file is in site folder
All I want to do is remove watch and details from the url like:
localhost/a/site/contact/
localhost/a/site/about/
Update
#Options -Indexes
#Options +FollowSymLinks
RewriteEngine On
#Exclude myadmin directory from the second level links
RewriteRule ^(myadmin)(/.*)?$ - [L]
RewriteRule ^(source)(/.*)?$ - [L]
ErrorDocument 404 /404.html
RewriteRule ^([a-zA-Z0-9_\-]+)/?$ index.php?task=$1 [L]
#Redirect 2nd level links to index.php
RewriteRule ^([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)?$ index.php?task=$1&slug=$2 [L]
#Redirect 3rd level links to index.php
RewriteRule ^([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)?$ index.php?task=$1&slug=$2&page=$3 [L]
#Redirect 4th level links to index.php
RewriteRule ^([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)?$ index.php?task=$1&slug=$2&title=$3&page=$4 [L]
I've tried following but this doesnot work
#RewriteRule ^/(.*)$ /watch/$1
RewriteBase /a/site
RewriteCond %{HTTP_HOST} ^/watch/
RewriteRule /(.*) /watch/$1 [QSA,L]
RewriteRule /(.*) /details/$1 [QSA,L]
RewriteRule /(.+) /watch/$1/index.php [NC,L]
RewriteCond %{THE_REQUEST} \ /+watch/
RewriteRule ^watch/(.*)$ /$1 [L,R=301]
Insert these 2 rules just below RewriteEngine On line in /a/site/.htaccess:
RewriteRule ^(contact)/?$ index.php?task=watch&slug=$1 [L,QSA,NC]
RewriteRule ^(about)/?$ index.php?task=details&slug=$1 [L,QSA,NC]

rewrite flag [L] is not working

This is my .htaccess file i just want to rewrite the page from one url to another.But it moved 404 page
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteRule ^([^/]+)/article/([^/]+)$ /index.php?option=com_vendorsearch&view=article&title=$2 [L]
RewriteRule ^([^/]+)/polls/([^/]+)$ /index.php?option=com_vendorsearch&view=polls&id=$2 [L]
RewriteRule ^([^/]+)/coupons/([^/]+)$ /index.php?option=com_vendorsearch&view=coupons&id=$2 [L]
RewriteRule ^([^/]+)/images/([^/]+)$ /index.php?option=com_vendorsearch&view=images&id=$2 [L]
RewriteRule ^([^/]+)/videos/([^/]+)$ /index.php?option=com_vendorsearch&view=videos&id=$2 [L]
Probably you need your first rules as:
RewriteRule ^[^/]+/articles/([^/]+)/?$ /index.php?option=com_vendorsearch&view=article&title=$1 [L,QSA,NC]

subdomain rewrite rule lithium framework

I plan to have this as a URL:
https://SubDomain.domain.com/<locale>/Controller/action/param1/param2/?query=param3
in Lithium Framework (li3.me)
What is the purpose of the htaccess files in Lithium?
It should redirect me through .htaccess as:
https://domain.com/<locale>/Conttroller/action/param1/param2/?query=param3&subdomain=SubDomain
In Lithium framework there are 3 .htaccess files:
1. /.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
2. /app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
3. /app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# Uncomment the line below, to enable HTTP authentication running PHP as a CGI.
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !favicon.ico$
RewriteRule ^ index.php [QSA,L]
</IfModule>
I tried to edit the root /.htaccess file to get the subdomain name as a parameter without any success.
Pass subdomain as parameter
Dynamic subdomain rewrite htaccess
.htaccess Wildcard Subdomains
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !mydomain\.com$ [NC]
RewriteRule ^(.*)$ app/webroot/$1?subdomain=%1 [L]
Do I have to rewrite rules in all 3 .htaccess files? If so, what are the changes needed?
Thanks!

.htaccess redirect all sub directories under sub directory

I want to redirect all sub directories under sub directory root/windows/ to root/windows/ct.php
File structure of site is like
root/windows/ct.php
Redirect these type of url
http://www.site.com/windows/games/ or http://www.site.com/windows/games
http://www.site.com/windows/software/ or http://www.site.com/windows/software
To
http://www.site.com/windows/ct.php?ct=games
http://www.site.com/windows/ct.php?ct=software
I am trying like this but it redirects all url to sub directory root/windows/ct.php
RewriteRule ^([^/]*)/ /Site/windows/?ct=$1 [L]
RewriteRule ^([^/windows]*)/ /Site/windows/?ct=$1 [L] // this one shows internal server error
Complete .htaccess code
Options +FollowSymlinks
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteRule ^(error) - [L]
RewriteRule ^[^/]*/[^/]*/(.*\.html) /Site/error/400/ [L]
RewriteRule ^([^/]*)/(.*\.html) /Site/software/?link=$1&id=$2 [L]
RewriteRule ^([^/]*)/ /Site/windows/?ct=$1 [L]
RewriteRule ^sitemap\.xml$ sitemap.php [L]
RewriteRule ^rss/(.*?)\.xml$ rss/$1.php [L]
</IfModule>
ErrorDocument 400 /Site/error/400/
I do not know well about .htaccess please see and suggest any possible way to do it.
Thanks.
Give this a try:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^windows/([^/]+)/?$ /windows/ct.php?ct=$1 [L]
</IfModule>
For your localhost use this one:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /Site/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^windows/([^/]+)/?$ windows/ct.php?ct=$1 [NC,L]
</IfModule>

Resources