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]
Related
I am using gltf objects on my website with three.js. And I am using pretty links rules on my htaccess file. If I browse this url : https://yeni.elbielectric.com/gett.php my object is loading and appearing on page. But if I browse this url : https://yeni.elbielectric.com/urunler/zena/silverline/fildisi/anahtar/ object is loading but not disappearing. And I cannot see any console error. I think beacuse of htaccess rules there is a problem. Here is my htaccess content :
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^urunler/$ products.php [NC,L]
RewriteRule ^urunler/(.*)/(.*)/(.*)/(.*)/(.*)$ product-detail.php?prdname=$1&prddetail=$2&prdcolor=$3&functype=$4 [L]
RewriteRule ^products/(.*)/(.*)/(.*)/(.*)/(.*)$ product-detail.php?prdname=$1&prddetail=$2&prdcolor=$3&functype=$4 [L]
RewriteRule ^urunler/(.*)/(.*)$ product-list.php?prdname=$1 [L]
RewriteRule ^products/(.*)/(.*)$ product-list.php?prdname=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
there are some paths about my 3d objects and texture on js code. I think there is a problem about them.
for example : "../../../../../Models/ZenaVega/zena.gltf"
What is wrong?
Thanks.
With your shown samples/attempts, please try following .htaccess rules file. Please make sure to clear your browser cache before testing your URLs.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^urunler/?$ products.php [NC,L]
RewriteRule ^(?:urunler|products)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ product-detail.php?prdname=$1&prddetail=$2&prdcolor=$3&functype=$4 [NC,QSA,L]
RewriteRule ^(?:urunler|products)/([^/]*)/?$ product-list.php?prdname=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.*)/?$ $1.php [L]
I have a static html website and I am using the following code to remove the .html extension for SEO reasons:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
Problem is when I add a subdirectory /blog/ I get a 403 Forbidden error. Any help please?
Try this, you were missing the html condition.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
I would like to delete extensions like .php, .html, etc from my url and this is what I use:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
It works but I don't know if this is the best way to do this and I also don't understand how it works, could someone explain it?
The second thing I would like to realise is to make the URL more beautiful by doing something like this:
this is my URL: http://domain.com/portfolio/project.php?id=1
this is what I would like to see: http://domain.com/portfolio/project/1
Thanks in advance
You can use these rules in site root .htaccess:
RewriteEngine On
# rewrite /portfolio/project/25 to /portfolio/project.php?id=25
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(portfolio/[\w-]+)/([\w-]+)/?$ $1.php?id=$2 [L,QSA,NC]
# rewrite /portfolio/project to /portfolio/project.php
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# rewrite /portfolio/file to /portfolio/file.html
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
Thanks for your help. I have been trying to solve this for an hour now.
I had this Htaccess that would rewrite /file.html to a script but decided to remove the extension and it turned out like this:
RewriteEngine On
#RewriteRule ^([^/]*)\.html$ /?file=$1 [L]
RewriteRule ^([^\.]+)$ /index.php?file=$1 [NC,L]
However, now I need it to work also with filename containing the dot (i.e. /file.with.dots) but that rule doesn't allow it.
This one works for files with dots but ending in .html
#RewriteRule ^(.*)\.html$ /index.php?file=$1 [NC]
This gets me an Internal Server Error
RewriteRule ^([^/]+)$ /index.php?file=$1 [NC,L]
You could just do this.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/?$ /index.php?file=$1 [NC,L]
Let me know the result.
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]