Need help with .htaccess
I have website on my localhost with this .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ website/index.php/$1 [L]
Now i want to move the site to subdomain.domain.com
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://subdomain.domain.com/index.php/$1 [L]
I chaged the url but this doesn'n work maybe because this is subdomain i don't know
hosting details:
# Subdomain Name Path [?]
1 subdomain.domain.com /home/www/subdomain.domain.com
my urls are like this
http://website/index.php/contact
with this htaccess i can use
http://website/contact
When i moved the site to the subdomain i can use http://subdomain.website/index.php/contact but when try http://subdomain.website/contact gives me error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Try with this one, it should work for all domains localhost as well as server.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Make sure "rewrite_engine = on" on server.
Related
How do I create dynamic .htaccess file that recognizes the server path. It needs to work on localhost folder which path is:
/Library/WebServer/Documents/myscaryproject/.htaccess
and on hosted server path which is:
/domains/mydomain/.htaccess
This is my .htaccess currently:
ErrorDocument 404 /myscaryproject/404.php
RewriteEngine on
# removing index.php from url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /myscaryproject/index.php?event=$1 [L]
# removing index.php and replacing it with event and page parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ /myscaryproject/index.php?event=$1&p=$2 [L]
RewriteRule ^login/?$ login.php [NC]
This all doesn't work if I push it to the server, because pathing isn't correct.
I try remove site to another domain. On the new domain site is located in a subfolder, and i have problem with htacces
htacces on my old domain mydomain.com
RewriteEngine on
RewriteCond $1 !^(index\.php|public|media|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
New site location is mydomain.com/site/
Links to pages and images are not good.
If it's in a subfolder you need to add the rewritebase. Make sure this .htaccess is also in /site/.htaccess
RewriteEngine on
RewriteBase /site/
RewriteCond $1 !^(index\.php|public|media|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I'm moving my site from the .com version to the .co.uk. The only issue is there are some admin facilities that I want to keep on the .com site. I've set up my .htaccess to redirect everything but requested files and directories that exist which works fine, except for the root of the site, I can't get that to redirect.
Here is my htaccess...
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ http://www.site.co.uk/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) http://www.site.co.uk/$1 [R=301,L]
You can use this code:
RewriteEngine On
RewriteBase /
RewriteRule ^(index\.php)?$ http://www.site.co.uk/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) http://www.site.co.uk/$1 [R=301,L]
This regex ^(index\.php)?$ will match index.php OR empty string (landing page).
I was wondering if it's possible to redirect all requests to files/directories that do not exist to index.php, and after that clean the url.
So when I go to www.example.com/test/1 I want it to be redirected (rewrote?) to www.example.com
I tried the following and it does correctly load index.php, but it still says www.example.com/test/1 in the URL bar...
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
Of course I still want my css and js to load properly...
Try this. If I understand, you want to use this as a way of redirecting a 404 not found?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [R=301,L]
Or maybe this without index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [R=301,L]
I am using codeigniter. I have front end application and backend application like
/system/
/application/
/front/
/admin/
index.php
admin.php
.htaccess
I want my url like http://example.com/news/article1 (for site)
http://example.com/news/admin (for admin)
In .htaccess I have written
RewriteEngine On
# If the user types just "admin".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/admin$ admin\.php [L,QSA]
# If the user enter in any admin section, like "admin/section".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/admin\/(.*)$ admin\.php/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
the front end is working fine but when I enter mydomain.com/admin it is throwing 404 not found error. Please help me.
Thanks and regards
I'm not that good with .htaccess, but from the CI website, you can use this for your .htaccess rule
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and then use routes to rewrite your urls. Much easier than trying to do it in .htaccess files