I am new to .htaccess so bear with me.
I am trying to have my URL look like:
http://example.com/login
Using .htaccess it uses:
http://example.com/index.php?url=login
My .htaccess looks like this:
RewriteEngine On
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
The problem with this is that when I try to access http://example.com/asset/style.css it just shows my index.php without being able to use my css. How can I change this to be able to use my css files?
Try
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php?url=$1 - [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Related
My folder structure is:
modules
admin
index.php
login
login.php
signup.php
articles
articles.php
My current URL is:
localhost/modules/admin/index.php
localhost/modules/login/login.php
localhost/modules/articles/articles.php
I want to change it to:
localhost/index
localhost/login
localhost/articles
Since i a beginner in using .htaccess file, pls help me how i can change the URL using .htaccess file
Your folder structure makes it difficult to have a universal rule but you should be able to use these rules.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(index)/?$ /modules/admin/$1.php [NC,L,QSA]
RewriteRule ^(login|articles)/?$ /modules/$1/$1.php [NC,L,QSA]
Try this
Options +FollowSymLinks
Options -Indexes
RewriteEngine On
RewriteRule ^index([^/]*) /admin/index.php [L]
RewriteRule ^login([^/]*) /login/login.php [L]
RewriteRule ^signup([^/]*) /login/signup.php [L]
RewriteRule ^articles([^/]*) /articles/articles.php [L]
I have the following code on my htaccess:
RewriteEngine On
RewriteRule ^course-details/([a-zA-Z0-9]+)/$ course-details.php?id=$1
I think this gave me a URL like this: /cp/course-details/5 where 5 is the id of the course.
But when I go to this address I get 404 not found. Also, our current url is
/cp/course-details.php?course-details.php?name=bla-bla-bla&category_id=1
and we need a friendly url like this
cp/category-name/course-name/
Thanks in advance for you help.
You can try this in your htaccess file if the php file is in the cp dir. Since it appears your are developing in a subfolder(peppers) of your dev box you can try this.
RewriteEngine On
RewriteBase /peppers/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cp/course-details/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
If this is for production then you can use this in the .htaccess file in the root.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cp/course-details/([^/]+)/?$ /cp/course-details.php?name=$1 [NC,L]
RewriteRule ^course-details/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/.*$ course-details.php?id=$1&category_id=$2
With that, you can use URL like course-details/1/5/category-name/course-name
Because URL allow: course-details/category_id/id/what-ever-you-want
I want to rewrite URL using .htaccess in codeigniter but it's not working. Can you please figure it out. Want to change URL from:
www.site.com/mauritius_holiday_rentals/apartment/anyname
to
www.site.com/mauritius_holiday_rentals/anyname
My current .htaccess file contains:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteRule ^mauritius_holiday_rentals/([A-Za-z0-9-]+)/?$ mauritius_holiday_rentals/apartment/$1 [L,QSA]
First four line is for removing index.php from URL which is working fine.
If routes file is set to access new url and you want to set redirection for old URLs then Use following code in .htaccess. otherwise let me know in detail what you want to do.
RewriteEngine on
RewriteBase /
RewriteRule /mauritius_holiday_rentals/apartment/$1 /mauritius_holiday_rentals/$1 [R=301,L]
Routes.php config file code
$route['mauritius_holiday_rentals/(:any)']="mauritius_holiday_rentals/apartment/$1";
Let me know if any problem.
RewriteEngine On
RewriteBase /yourProjectName/
RewriteCond $1 !^(images|stylesheets|javascript)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourProjectName/index.php?/$1 [L]
Try to use codeigniter routing system
https://www.codeigniter.com/user_guide/general/routing.html
I made a PHP framework that has a built in TPL system. It fetches the ending of the url, and finds the file that has that string. So if the url is http://website.com/tagHere the Tpl system would look for the file called tagHere.php. Everything works fine with it, but I'm now trying to expand the framework to have a built-in backend panel. I've tried multiple ways, but it just refuses to work.
I decided to take a look at Wordpress' htaccess, since they do exactly what I'm trying to accomplish. Here is how their htaccess works.
They check if the requested file name is a file. If it isn't a file, then they check if it is a folder. If it isn't a folder, they redirect to index.php. I want it to check if it's a file/folder, and if it isn't to remove the .php tag from the URL, so the TPL system can get the specified file and return it.
Here was my original .htaccess file.
RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1`
Here is Wordpress' original .htaccess file.
<ifmodule mod_rewrite.c="">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</ifmodule>
Here was my attempt:
<ifmodule mod_rewrite.c="">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1
</ifmodule>
When I try the above htaccess, it returns a 404 error.
The Rule
RewriteRule . /index.php [L]
Will always match every URL because it says something like "if there is a character in the URL, then redirect".
What you're looking for is something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin/(.*?)$ admin.php?location=$1 [L]
RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1
i have problems in rewriting url's in my site
when i rewrite url's site styles dont work
i write this code in htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_URI} !Resources/css/(.*)
RewriteRule ^/?(index.(html|php|java|jsp|asp))?$ controller.php
RewriteRule ^LoadPage/(.*) controller.php?LoadedPage=$1 [QSA]
RewriteRule ^Admin/(.*) controller.php?Page=Admin&Section=$1 [QSA]
RewriteRule ^(.*) controller.php?Page=$1 [QSA]
but when i write this url for example:
localhost/sitename/Admin/Users
the page Users successfully rendered , but without style !
I think you will find a good answer over here
.htaccess
You can also redirect everything that is not an actual file directory to your controller like so:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . controller.php [L]
</IfModule>