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]
Related
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]
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]
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]
I am accessing the following URL:
http://example.com/welcome
Where I have the following .htaccess
RewriteEngine On
RewriteRule ^(.*)$ /index.php?package=base&page=$1 [L]
I am expecting to return
package=base
page=welcome
But instead is giving me a "500 Internal Server Error".
If I change the htaccess to
RewriteEngine On
RewriteRule ^we(.*)$ /index.php?package=base&page=$1 [L]
It returns:
package=base
page=lcome
As expected, and if I change the htaccess to
RewriteEngine On
RewriteRule ^(.*)me$ /index.php?package=base&page=$1 [L]
It returns:
package=base
page=welco
As I was expecting as well.
Now the question is... why it does not math the whole URL? What I am missing here? How can I say "take everything the user passes and put it on a variable"?
Thanks!
The rewrite engine loops, so without some sort of conditions, the regex ^(.*)$ matches index.php and so on. Try
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?package=base&page=$1 [L]
I am completely beginner to htaccess, I am trying to shorten my following url..
From
http://website.com/index.php?student-name=john
http://website.com/index.php?teacher-name=amy
http://website.com/index.php?class=xxx
To
http://website.com/john
http://website.com/amy
http://website.com/xxx
I have tried following .htaccess code,
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?student-name=$1 [L]
RewriteRule ^([^/]+)/?$ /index.php?teacher-name=$2 [L]
RewriteRule ^([^/]+)/?$ /index.php?class=$3 [L]
but, i shows "500-Internal servor error"....
EDIT :
when i am trying to use one rewrite_rule, its works fine. Like
RewriteRule ^([^/]+)/?$ /index.php?student-name=$1 [L]
(or)
RewriteRule ^student/([^/]+)/?$ /index.php?student-name=$1 [L]
when i am trying to use two or more rewrite_rule, its shows "500-Internal servor error". Like
RewriteRule ^([^/]+)/?$ /index.php?student-name=$1 [L]
RewriteRule ^teacher/([^/]+)/?$ /index.php?teacher-name=$1 [L]
(or)
RewriteRule ^student/([^/]+)/?$ /index.php?student-name=$1 [L]
RewriteRule ^teacher/([^/]+)/?$ /index.php?teacher-name=$1 [L]
Its shows error log is: "Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace."
what's that mean?
This is a bad idea. Why? How does Apache know if the string in the first path segment is a student, teacher or class? It doesn't, so it will always rewrite to a student-name.
Instead use urls like:
http://example.com/student/john
http://example.com/teacher/amy
http://example.com/class/xxx
Now the rewrite is trivial, since each group has a common prefix.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^student/([^/]+)/?$ /index.php?student-name=$1 [L]
RewriteRule ^teacher/([^/]+)/?$ /index.php?teacher-name=$1 [L]
RewriteRule ^class/([^/]+)/?$ /index.php?class=$1 [L]
As for the 500 internal server error you need to check your Apache error log. Make sure that mod_rewrite is enabled, and that you restarted your Apache after you did this. Besides the rules, I changed the lowercase l in FollowSymLinks into an uppercase L, but I am unsure if this can cause any problems.