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>
Related
I have created my own cms and i find the following issue. The pages links show as this:
https://www.example.com/page/contact-us
I want them to show as this, by removing the page alias:
https://www.example.com/contact-us
My Htaccess:
Options -MultiViews
RewriteEngine On
RewriteRule ^page/([\s\S]*)$ single-page.php?slug=$1 [L]
I have tried this but doesn't work for me
RewriteEngine On
RewriteRule ^([^/]*)$ /page/single-page.php?slug=$1 [L]
RewriteRule ^([^/]*)$ /page/single-page.php?slug=$1 [L]
This won't work because it is forwarding all URIs to /page/ directory which obvious doesn't exist.
You should be using this rule:
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ single-page.php?slug=$1 [L,QSA]
This might be something simple, but I spent days on it, without results.
My website home page URL by default is
https://rezume.am/index.php?controller=pjLoad&action=pjActionJobs
I want to see https://rezume.am/ instead.
When I added the following rule in .htaccess file:
RewriteRule ^()$ index.php?controller=pjLoad&action=pjActionJobs$1
Things worked, but filters on the left got broken.
Here is my whole .htaccess content:
#Redirection code starts
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Redirection code Ends
RewriteEngine On
RewriteRule ^(.*)-(\d+).html$ index.php?controller=pjLoad&action=pjActionView&id=$2
RewriteOptions inherit
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase //
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . //index.php [L]
#RewriteRule ^(.*)$ index.php/$1 [PT,L]
RewriteRule ^()$ index.php?controller=pjLoad&action=pjActionJobs$1
</IfModule>
Could anyone please advise a better rule to skip controllers and actions and see just domain?
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 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