I use the following code on the main domain (www.exemple.com) in a htaccess file to make url more friendly:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^seite-([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$ /index.php?page=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*).html$ /post.php?id=$1
But this does not work on my subdomain (m.exemple.com). Same issue if I put a htaccess file in the subdomain folder.
Has someone a solution for that ?
Thanks in advance,
Oliver
Related
I have three directories
phone/
email/
profile/
In the phone directory I would have for example phone/555-555-1212.html
I would like to use htaccess to call my php file and search mysql
that page is /phone/template.php?a=555&b=555&c=1212
Email same thing
email/jay#gmail.com.html
php page /email/template.php?email=jay#gmail.com
Profile page would be
/profile/123456.html
to call /template/profile.php?id=123456
Please help
Thanks!!
Right now in my profile folder I am practicing and have this but if I do not have anything else after the profile/ it just pulls a blank page
I am a complete rookie to htaccess and am trying to learn
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9_-]+).html$ index.php?ter_id=$1 [QSA,L]
put this in the root's .htaccess:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#----- Email Rewrite
RewriteCond %{REQUEST_URI} email/([^/]+) [NC]
RewriteRule .* email/email_template.php?email=%1
#----- Profile Rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} profile/([^/]+) [NC]
RewriteRule .* profile/profile_template.php?profile=%1
#----- Phone Rewrite
RewriteCond %{REQUEST_URI} phone/([^/]+)-([^/]+)-([^/]+) [NC]
RewriteRule .* phone/phone_template.php?a=%1&b=%2&c=%3
P.S: DO NOT forget to sanitize the $_GET['foo'] in your pages and remove any unneeded symbol
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 want to use .htaccess files so that if someone visits an old URL on our new website such as website.com/oldpage.asp .htaccess first checks to see if website.com/oldsite/oldpage.asp is on our server. And if no file is there redirect them to old.website.com/oldpage.asp where a copy of our old website exists.
For some reason only the .htaccess file in the /oldsite/ folder is executing.
Here is my .htaccess file for my site root which checks if the file exists on the new site and if not redirects to /oldsite/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /oldsite/$1 [NC,QSA,L]
Then in /oldsite/ its supposed to check if the file again exists, and if not redirect again.
RewriteEngine On
RewriteOptions inherit
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://old.website.com/$1 [R=301,NC,QSA,L]
You don't need 2 .htaccess for this.
Have this rule in site root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/oldsite/$1 -f
RewriteRule ^(.*)$ oldsite/$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://old.website.com/$1 [R=301,L]
Then remove /oldsite/.htaccess and test this after clearing your browser cache.
I want to redirect
www.domain.com/abc
to
www.domain.com/index.php?a=abc
only if the folder abc doesn't already exist.
How should I write the .htaccess file?
Try
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ http://www.domain.com/index.php?a=$1 [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