htaccess is not working after changing server with codeigniter - apache

i am using codeigniter with .htaccess
in older server i had following rules in .htaccess file
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^transaction\.php$ index.php/printer_api/transaction/%1/%2/%3/%4/%5/%6/%7/%8 [L]
RewriteRule ^getlist\.php$ index.php/printer_api/getlist [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
it was working fine.
but after moving the website to a new server the URL .htaccess wasn't working
it was showing "Input file is not specified"
after searching the web i found a solution that is:
changing the Rule in last line from:
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
to (adding extra ? just after index.php):
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
this solved generic URL rewrite with codeigniter.
but still i have problem with following part those are specific for separate URL:
RewriteRule ^transaction\.php$ index.php/printer_api/transaction/%1/%2/%3/%4/%5/%6/%7/%8 [L]
RewriteRule ^getlist\.php$ index.php/printer_api/getlist [L]
in the first URL there are maximum 8 parameters (but the number of parameter can vary in different case
and in the second URL there is no parameter.
but these URLs are not working in new server.
now can anyone please help to make those two Rule working.

Not sure if it'll work, but did you try a similar solution as the one for index.php? Something like:
RewriteRule ^transaction\.php$ index.php?/printer_api/transaction/%1/%2/%3/%4/%5/%6/%7/%8 [L]
RewriteRule ^getlist\.php$ index.php?/printer_api/getlist [L]

Related

Redirecting all subfolders to URL with GET parameters

Quick question for redirecting rules. I'm making a url shortener service and I'd like to have all my links from:
http://www.shortener/url
to :
http://www.shortener/index.php?p=url
I tried on my OVH .htaccess the following code:
RewriteEngine On
RewriteRule ^/(.*)$ index.php?p=$1 [R=301,L]
But this does not work, I tried with removing the "/":
RewriteEngine On
RewriteRule ^/(.*)$ index.php?p=$1 [R=301,L]
But I have a ERR_TOO_MANY_REDIRECTS error on my page.
What should I do?
Why you are seeing error because you have infinite loop occurred there, so we need to place a condition there. Could you please try following, based on your shown samples. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^(.*)/?$ index.php?p=$1 [L]

htaccess rewrite rule does not work

I am facing problem with rewrite rule in htaccess file. Please help.
This is my current htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /product-project/
RewriteRule . index.php [L]
</IfModule>
Now I want to create a rewrite rule such as "product/category/id" should redirect to "product/profile?profile_id=id". For this I have used
RewriteRule ^product/.*/(.*)$ product/profile?profile_id=$1 [L,R]
which is working fine in some way.
1st problem -> It is redirecting properly, but URL also changes. It should stay as "product/category/10", if I use the id as 10. But when I use this, it is redirecting properly, but URL changes to "product/profile?profile_id=10". I read somewhere to use [L,P] instead of [L,R] , but it is giving as Server error.
2nd problem -> Now I want to create a new rewrite rule such as "product/id" should also redirect to "product/profile?profile_id=id". For this I have used
RewriteRule ^product/(.*)$ product/profile?profile_id=$1 [L,R]
Now this is not working & showing server error
3rd Problem -> Can I also create a new rewrite rule such as "/id" should also redirect to "product/profile?profile_id=id". Is this possible ?
4th Problem -> Can I also create a new rewrite rule such as "/id1/id2" should also redirect to "product/profile?profile_id=id1&serial_id=id2". Is this possible ?
Thanks in advance for your time.
Is this what you want please check.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ $1/$2?profile_id=$3
for two id's
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ $1/$2?profile_id=$3&id=$4
Use it..
Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Rewrite URL with subdirectory and file

i am trying to use .htaccess to rewrite the URLs for my site, here is what i would like
currently, the urls look like this
http://www.mysite.biz/store/cart.php?m=new_arrivals
All of the sites are loaded using php GET and the only thing that ever changes is the query string after cart.php so i would like to rewrite to....
http://www.mysite.biz/cart.php?m=new_arrivals
I have been searching all over the internet and have tried out various techniques to do this and none of them have worked. i've tried this...
RewriteRule ^store/(.*)$ http://www.mysite.biz/$1 [R=301,L]
this...
RewriteCond %{REQUEST_URI} ^/store($|/)
RewriteRule ^.*$ /store/cart.php [L]
and this...
RewriteCond $1 !^store
RewriteRule ^(.*) /store/$1 [L]
ive been developing web for a while now but this is my first time really doing anything with .htaccess and i am totally stumped. any help will be greatly appreciated
Try this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+store/(cart\.php[^\s]+) [NC]
RewriteRule ^ /%1 [R=302,L]
RewriteRule ^(cart\.php)$ /store/$1 [L,NC]

subdomain htaccess

I have here a subdomain which i wish to pass on.
here the example of url : http://subdomain.domain.com/login
and it should point to : http://subdomain.domain.com/index.php/login
i write a simple htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|images|robots\.txt|css|javascript)
RewriteRule ^(.*)$ index.php/$1 [L]
but i always get 500 server error. any body have idea where i wrong?
thanks for any help
It's normal, you go to http://subdomain.domain.com/login, get redirected to http://subdomain.domain.com/index.php/login, then to http://subdomain.domain.com/index.php/index.php/login and so on because you RewriteRule always match.
You can write `RewriteRule ^([^/]*)$ index.php/$1 [L]
Make sure Apache rewrite module is active and your .htaccess file has the following line before any rewrite rule:
RewriteEngine On
Assuming you have mod_rewrite enabled, your RewriteRule causes an infinite redirection loop, which exceeds the maximum number of redirects and causes an internal server error.
You need to condition your rule so it only rewrites once. For example, this should work:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]

mod_rewrite to a directory

Im trying to create a rewrite rule to a different directory, but unfortunatly its not working.
My current rewrite sends everything back to the index.php file unless the first word in the query string is admin. The rewrite rule for 'admin' is to admin.php, but i actually want it to go to /var/www/html/website.com/admin/admin.php (instead of the file in the same directory).
This is current .htaccess file.
RewriteEngine On
RewriteRule ^(.*\/?).*(css|images|js/)+.*$ - [L]
RewriteRule ^\/?admin\/?(.*)$ admin.php?url=$1 [QSA,L]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
If i change the rewrite rule for admin to use a different directory..
RewriteRule ^\/?admin\/?(.*)$ /var/www/html/website.com/admin/admin.php?url=$1 [QSA,L]
It breaks the site. Any ideas?
Thanks.
It's actually quite simple, you're using the system path, while web path is needed.
Try the following line:
RewriteRule ^\/?admin\/?(.*)$ /subfolder/admin.php?url=$1 [QSA,L]
Try these rules:
RewriteRule ^admin($|/(.*)) admin/admin.php?url=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?url=$0 [QSA,L]