htaccess not rewriting urls correctly - .htaccess

i've encountered the following problem:
The .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule view/^(.*)$ view.php?id=$1 [L,QSA]
Is not rewriting my urls
The friendly URL should be like this
https://domain.tld/view/1
And the original url should be rewritten like this:
https://domain.tld/view.php?id=1
The result of the htaccess above is a 404.

Try
RewriteRule ^view/(.*)$ view.php?id=$1 [L]

Related

htaccess rewrite going to 404?

for the last hours I cant seem to figure out why my .htaccess file is redirecting to a blank url. Here is my htaccess file below.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-l
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^(.*)$ /test/user-profile/%1? [R=301,L]
I am trying to rewrite www.example/test/user-profile?id=4 ->>> www.example/test/user-profile/4
It does rewrite the url, however then the page has "The requested URL was not found on this server." the htaccess file is in public_html folder, so I am trying to select a specific user inside www.exampleurl.com/test/userslist.php which would go to www.exampleurl.com/test/user-profile.php. It all works perfectly before using htaccess. www.example/test/user-profile?id=4 ->>> www.example/test/user-profile/4 but it just wont find the url or file? im a super noob folder path below -> public_html/test/userslist.php & user-profile.php
Just cant seem to figure out what to do. Yes I do have mod-rewrite on.
With your shown samples, please try following htaccess rules file.
This assumes that you are hitting link www.example/test/user-profile?id=4 in browser which is redirecting to www.example/test/user-profile/4 and is being served by index.php with parameters user-profile=user-profile in your url and id=digits in url. You can also change them as per your need.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine On
RewriteBase /test/
RewriteCond %{THE_REQUEST} \s/(test/user-profile)\?id=(\d+)\s [NC]
RewriteRule ^ %1/%2? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]*/)/([*/]*)/?$ test/user-profile.php?user-profile=$1&id=$2 [QSA,L]
2nd solution: In case someone is hitting url example.com/test/user-profile/7 then try following htaccess rules.
RewriteEngine On
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]*/)/([^/]*)/(\d+)/?$ test/user-profile.php?user-profile=$1&id=$2 [QSA,L]

.htaccess mod_rewrite web.com/text to web.com/index.php?page=text

I would like to redirect (mod_rewrite) the URL that user enters to another.
User enters:
www.example.com/text
And the URL to display should be:
www.example.com/index.php?test
I have this .htaccess file, but it does not work (I get 404 error):
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ ?page=$1 [L,QSA]
Where am I wrong?
Thanks everyone

.htaccess rewrite url showing 404 not found

i want to change this URL
domain.com/adsbycat/sub_category.php?category=car-and-buses&category_id=1&sub_category=Car
to
domain.com/car-and-buses/1/Car
i write this code to do this
RewriteEngine On
RewriteBase /domain.com/
RewriteRule ^adsbycat/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ adsbycat/sub_category.php?category=$1&category_id=$2&sub_category=$3
but when i request for new URL it showing 404 not found. please fix this code.
Have this rule in site root .htaccess to rewrite domain.com/car-and-buses/1/Car:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/[^/]+/(.+)$ adsbycat/sub_category.php?category=$1&category_id=$2&sub_category=$3 [NC,L,QSA]

Rewriting subfolders using nice url

When I go to http://www.example.com/youtube/detail/abvcde in my browser, I want to internally rewrite the url to http://www.example.com/youtube/detail.php?id=abvcde. I tried to do this with the following .htaccess, but it gives a 404 error.
Currently my .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
Put the following code in a htaccess file in server root directory:
RewriteEngine On
RewriteRule ^youtube/detail/(.+)$ youtube/detail.php?id=$1 [L]
You can put this code in your /youtube/.htaccess
Options -MultiViews
RewriteEngine On
RewriteBase /youtube/
RewriteRule ^detail/([^/]+)$ detail.php?id=$1 [L]

URL rewrite using .htaccess

I need a URL like
mydomain.com/myname/?action=post&data=10
Here in a single PHP page (user.php), I need all myname, post and 10 as GET method variables. How can I get it using .htaccess?
you can add the following to .htaccess
RewriteEngine On
RewriteBase /myname/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]

Resources