url rewrite 404 - Not found - .htaccess

i tried this to rewrite url,and worked perfectly
Options +FollowSymLinks
RewriteEngine on
RewriteRule download-id-(.*)\.htm$ download.php?id=$1
but when i tried to rewrite download.php?id=xx to download.php/id/xx by the following:
Options +FollowSymLinks
RewriteEngine on
RewriteRule download/id/(.*)/ download.php?id=$1
RewriteRule download/id/(.*) download.php?id=$1
i got an 404 - Not found! error
what's the problem
i used this good tool to generate the syntax
http://www.webconfs.com/url-rewriting-tool.php

You need to make it:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^download/id/([0-9]+)\/?$ download.php?id=$1
the /? means it can have a trailing slash or not, and the ^ and $ start and end the search string.

Related

.htaccess hide sub-subdirectory in url

Looked for an answer but couldn't find one that solved my specific issue.
The Manager of my website is located under /manager/php an and want to remove the "php" from the URL.
For example https://example.com/manager/php/topkek.php would become https://example.com/manager/topkek.php.
Tried this but it gives an internal server error probably because of infinit redirects:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^manager/(.+)$ /manager/php/$1 [L]
Your rule causes an infinite rewrite loop as your pattern ^manager/(.+)$ also matches the substitution string /manager/php/$1 . You need to fix it so that the pattern can not match the destination path. You can exclude the /php path in your regex to fix the error.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^manager/((?!php).+)$ /manager/php/$1 [L]
Or you can use a RewriteCond directive to exclude the destination path
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/manager/php
RewriteRule ^manager/(.+)$ /manager/php/$1 [L]

How to create clean url using .htaccess for multiple parameters

This is my .htaccess code to rewrite clean url.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+download\.php\?id=([^\s&]+) [NC]
RewriteRule ^ download/%1? [R=301,L]
RewriteRule ^download/([^/]+)/?$ download.php?id=$1 [L,QSA]
This code works fine for single parameter in url. For example it rewrites www.mysitename.com/download.php?id=123 to www.mysitename.com/download/123
But when I tried to pass multiple parameters in url, all I got are errors. Searched various resources and related questions but didn't got proper solution.
I need a url like www.mysitename.com/download/123/file-name instead of www.mysitename.com/download.php?id=123&name=file-name
I guess I've to use something thing like this RewriteRule ^(.*)/(.*)$ download.php?id=$1&name=$2. But while implementing I'm getting 404 error. How can I alter My code to pass multiple urls. Thanks in advance.
You just need to add a parameter in your rule
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+download\.php\?id=([0-9]+)&name=([^\s&]+)\s [NC]
RewriteRule ^ download/%1/%2? [R=301,L]
RewriteRule ^download/([0-9]+)/([^/]+)/?$ download.php?id=$1&name=$2 [L]

mod_rewrite not working with my simple url

The problem is that I cannot make my URL change with the mod_rewrite, the URL I have is this:
http://example.org/files/news.php?news=180
I wish to see something like this:
http://example.org/files/news/180
I've tried these code (every single commented RewriteRule):
# Do not remove this line, otherwise mod_rewrite rules will stop working
# RewriteBase /
ErrorDocument 404 http://mysite.org/notfound.php
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /files/
#RewriteRule ^(.*)/ news.php?news=$1
#RewriteRule ^/news/([0-9]+) /news?news=$1
#RewriteRule ^(.*)/ files/news.php?news=$1 [L]
RewriteRule ^(.*)/(.*)/ news.php?news=$1 [L]
And nothing, How do the code should look like?? thanks
Place this code in /files/.htaccess:
ErrorDocument 404 http://mysite.org/notfound.php
Options +Indexes +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /files/
RewriteRule ^news/([^/.]+)/?$ news.php?news=$1 [L,QSA]

Not redirecting for clean URL

So I'm running into an issue here that I believe I have correct yet it's just not working for me here.
So simple enough I want me current URL which is:
tremorelights.com/chandelier-c-18.html?page=2&osCsid=vtemi4nqlioftbteam6nap0s77
To look like this URL:
tremorelights.com/chandelier/2/
So I'm trying to redirect it to the clean URL and this is what I have now.
RewriteEngine On
RewriteBase /
RewriteRule ^chandelier-c-18.html?page=$1 chandeliers/([0-9]+) [QSA,L,R=301]
Yet this is not working at all. When I manually input the clean URL it does not give me a 404 error but it does not take me to any other page like it should.
You can match against the query string in a rewrite rule, what you want to match against is the %{THE_REQUEST} variable here.
Try:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \ /+chandelier-c-18.html\?page=([0-9]+)
RewriteRule ^ chandeliers/%1? [QSA,L,R=301]
then maybe:
RewriteRule ^chandeliers/([0-9]+) chandelier-c-18.html?page=$1 [L]
Change your rule to this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^chandeliers/([0-9]+)/?$ chandelier-c-18.html?page=$1&osCsid=vtemi4nqlioftbteam6nap0s77 [QSA,L,NC]

.htaccess Rewrite Rule 404 Error

I am trying to get /game/game-name/ to redirect to /game.php?g=game-name
The code I am using in my .htaccess is:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^game/([a-zA-Z0-9]+)/$ game.php?g=$1
But when I go to /game/game-name/ I get a 404 Error. Any help would be appreciated.
Thanks!
That's because your rule transform this url /game/game-name/ into this /game/game-name/game.php?g=game-name
What you need to do is either this :
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^game/([a-zA-Z0-9]+)/$ /game.php?g=$1
Or this :
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^game/([a-zA-Z0-9]+)/$ game.php?g=$1

Resources