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
Related
I try to redirect url from
http://localhost/manual/$
to
http://localhost/manual/index.php?type=post&post=$
My file .htaccess is
RewriteEngine On
RewriteBase /manual/
RewriteCond %{REQUEST_FILENAME} !-f # Existing File
RewriteCond %{REQUEST_FILENAME} !-d # Existing Directory
RewriteRule . /manual/index.php? [L]
RewriteRule ^([^/]*)\/$ type=post&post=$1 [L]
But nor working whats wrong, help, sorry if duplicate because I still not understand to create htaccess.
You can use the following rule in /manual/.htaccess :
RewriteEngine on
RewriteBase /manual/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?type=post&post=$1 [L]
My url is http://example.com/product/Braided/table-fan
And i want to rewrite like this http://example.com/Braided/table-fan
where product is my php file.
Current rules:
Options +MultiViews +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ product/$1/$2/$3
RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ product.php?uname=$1&pid$2
Try and use this in your root .htaccess:
RewriteEngine On
RewriteRule ^$ product/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ product/$1
This should remove product from your URL and leave you with: http://example.com/Braided/table-fan.
Make sure you clear your cache before testing this.
I'm trying to rewrite some dynamic page url in which data is taken from database with slug like "this-is-a-link".
Options +FollowSymlinks
RewriteEngine On
RewriteBase /testweb/
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ faq_pages.php?page=$1 [QSA,L]
It works fine with http://www.test.com/testweb/this-is-a-link
But I need to change the rewrite rule based on any link clicked as below.
http://www.test.com/testweb/faq/this-is-a-link, 'testweb/news/this-is-another-link','/testweb/testimonials/test-link'
The "faq_pages.php" in the above RewriteRule should be changed to "news_pages.php". How can I have it dynamically so that I can use for every page with same htaccess or how can I check and rewrite the value to different pages in htaccess.
Also please advice me how to correct below code.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.html$ faq_pages.php?page=$1
I need to show html urls in the address bar like '/testweb/this-is-a-link.html' or '/testweb/faq/this-is-a-link.html'
Edit: By the help of Jon Lin I have updated my codes as below.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /testweb/
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^faq/(.*?)/?$ faq_pages.php?page=$1 [QSA]
Now both below conditions are working :
/testweb/faq/another-faq-test.html,
/testweb/faq/another-faq-test.html/
As I don't have any sub-folder with name 'faq' the template files(images/css/js etc) in root folder are not loading.
How can I fix it?
Thanking you
Are you looking for something like this?
Options +FollowSymlinks
RewriteEngine On
RewriteBase /testweb/
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^faq/(.*)$ faq_pages.php?page=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^news/(.*)$ news_pages.php?page=$1 [QSA,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
I have an htaccess file that is supposed to be redirecting any non-existing files/folders/etc into the application's index.php script where they are handled by the application's SEO rewriting.
The problem is that any missing images are also redirecting into the application which is causing a lot of additional load and is unnecessary. I've been attempting to get this htaccess file to ignore images, but even though this should be working, it's not, and I'm completely out of ideas as to why...
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !.*\.(gif|png|jpe?g|ico|swf)$ [NC]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?sef_rewrite=1 [L]
When I make a request to http://www.domain.com/folder_that_doesnt_exist/image.jpg this redirects to index.php
When I make a request to http://www.domain.com/folder_that_does_exist/image.jpg it also redirects to the index script
I'm not sure what I'm missing here because unless OR is specified, shouldn't the RewriteRule only be applied if the request passes all of the RewriteCond statements? which it clearly should not be passing...
Update:
I've modified the code to the following just to eliminate possible issues, but it still redirects all non-existing images into the script...
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(gif|png|jpe?g|ico|swf)$ [NC]
RewriteCond %{REQUEST_FILENAME} !\.(gif|png|jpe?g|ico|swf)$ [NC]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?sef_rewrite=1 [L]
Maby try this:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} \.(gif|png|jpe?g|ico|swf)$ [NC]
RewriteRule .* - [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]