I have a URL like this: http://www.domain.com/index.php?token=123
I want to rewrite the url to this: http://www.domain.com/123 or http://www.domain.com/123/
With this htaccess i can access http://www.domain.com/123/ but my css is then not loaded.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]
RewriteRule ^([^/]+)/$ index.php?token=$1 [L]
Regards
If I guess right than is your problem that you link relativ to your css file. So you need to correct the path to your css file.
Related
I have the next question to you about .htaccess files. This is my folder hierarchy:
ROOT
- docs
- index.html
- terms.html
- privacy.html
- .htaccess
This is following .htaccess file content:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
When I do following request:
https://example.com/docs/terms
The link in my browser looks like:
https://example.com/var/www/html/docs/terms.html
And I want to achieve this:
https://example.com/docs/terms.html
When I do https://example.com/docs/ I receive content from index.php file. How to fix my issue?
How you see the redirect without the R flag?
Try to change
RewriteRule ^(.*)$ $1.html [NC,L]
by
RewriteRule ^(.*)$ /$1.html [L,R=301]
/ is the important thing
I need help with my htaccess file. I added the following to remove all .php extensions which is working fine.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
However I have a directory /users which I want to rewrite the URL strings. The current URL is like this:
aero.site/maki/users/index.php?t=mf5cc
I want the URL to look like
aero.site/maki/mf5cc
I used the following rewrite rule but it's giving me Object not found error:
RewriteRule ^([^/.]+)$ users/index.php?t=$1 [L]
My complete htaccess content is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^/.]+)$ users/index.php?t=$1 [L]
Kindly help me with the correct rewrite rule for the last line to turn aero.site/maki/users/index.php?t=mf5cc into aero.site/maki/mf5cc
FYI: my htaccess file is in aero.site/maki directory
I finally got it to work. Thanks to #misorude. Here's my updated .htaccess content:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^/.]+)$ users/index?t=$1 [L]
I am using mod_rewrite in .htaccess. I can't figure out how to get the following done.
All css pages should go to /minify/?f=/styles.css
All js pages should go to /minify/?f=/js.js
All .txt, .gif, .jpg, .png files should open as they are
All other pages (eg: /page, /dir/page, /dir1/dir2/page) should go to /page.php
All other files in directories should open as it is (eg: /admin/login.php)
Edit:
This is the code that I came up with. It's not elegant, and it fails sometimes. For eg: I can't get /admin/login.php to work. When I open that URL, it's going to page.php.
RewriteEngine on
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|\.txt)$
RewriteRule .* page.php
RewriteRule ^.*?\.css$ /min/?f=/styles.css [L]
RewriteRule ^.*?\.js$ /min/?f=/js.js [L]
Try the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(css|js|png|txt|gif|jpe?g)$
RewriteRule ^ /page.php [L]
RewriteRule \.css$ /minify/?f=/styles.css [NE,L]
RewriteRule \.(js)$ /minify/?f=/$1.$1 [NE,L]
I have link like this for example http://localhost/somepage.php?id=1. And i want to make link like this http://localhost/somepage/1 but not just on somepage.php but for all pages on localhost. Here is my code for hidding .php extension and now i now i got http://localhost/somepage?id=1 and now i need to get http://localhost/somepage/1.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
You can replace your rule with this rule:
RewriteEngine On
RewriteRule ^([^/]+)/(\d+)/?$ $1.php?id=$1 [QSA,L]
When I don't edit my .htaccess file, my image path reads something like: http://this.website.com/codeigniter/inc/images/logo.jpg.
However, as soon as I add this code into the .htaccess file:
RewriteEngine On
RewriteCond $1 !^(index\.php)
RewriteRule ^(.+)$ index.php?$1 [L]
(to remove the index.php from the URL), I get 404 error, even with the exact same path.
How do I remove index.php and still have access to my images?
RewriteEngine On
RewriteCond $1 !^index\.php [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?$1 [L]
The two new RewriteConditions would exclude existing directories and files (and so images) from redirection.