500 err when access URI that has RewriteRule - .htaccess

Im getting error 500 when trying to access a URL that i already made made RewriteRule for
.htaccess
Options +FollowSymlinks
RewriteEngine On
//
RewriteRule ^/user/(.*)$ /user.php?un=$1 [NC]

Try this
Options +FollowSymlinks
RewriteEngine On
# coments on htaccess with # caracter
RewriteRule ^\/user\/(\w)*$ /user.php?un=$1 [NC]

Try :
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^/?user/(.*)$ /user.php?un=$1 [NC,L]

Removed //
And / from url it worked well
Options +FollowSymlinks
RewriteEngine On
#
RewriteRule ^user/(.*)$ user.php?un=$1 [NC]

Related

How could I rewrite urls properly?

I have URLs like http://url.com/top_admin/order.php?do=view&oid=124 and
I need to rewrite it to http://url.com/top_admin/order/view/124 , where
top_admin is a folder that contains my script.
this is my code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^order/(.*)/([0-9]+) order.php?do=$1&oid=$2 [L]
but it does not work.
With your shown samples/attempts, please try following. Please make sure to clear your browser cache before testing your URLs.
Options +FollowSymLinks -MultiViews
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(top_admin/order)\.php\?do=([^&]*)&oid=(\d+)\s [NC]
##Rule for external rewrite with 301.
RewriteRule ^ /%1/%2/%3? [R=301,L]
##Rule for internal rewrite to .php file.
RewriteRule ^([^/]*)/([^/]*)/(.*)/?$ $1.php?do=$2&oid=$3 [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]

Replace lowercase word in .htaccess

The pages on my site don't work if you access them by a url which is all lowercase
e.g.
mysite.com/product-category/mens doesn't show correctly
but
mysite.com/product-category/mens does show correctly.
I want to try the .htacess route first of all, but I can't get this to work. What i've tried is the following:
Options +SymLinksIfOwnerMatch +FollowSymLinks -MultiViews
RewriteRule ^/product-category/mens/(.*)$ ^/product-category/Mens/$1 [L]
and
RewriteCond %{QUERY_STRING} ^mens [NC]
RewriteRule ^ %{REQUEST_URI}/Mens [R,L]
But i've very new to .htaccess files and after almost two hours of searching i've decided to ask for help.
Thanks in advance
*********ANSWER***********
Thanks Jon Lin for the solution:
RewriteRule ^product-category/mens/(.*)$ product-category/Mens/$1 [L,R]
RewriteCond %{QUERY_STRING} ^mens(.*)$
RewriteRUle ^ %{REQUEST_URI}?Mens%1 [L,R]
Your first rule is close, you need to remove the leading slash:
Options +SymLinksIfOwnerMatch +FollowSymLinks -MultiViews
RewriteRule ^product-category/mens/(.*)$ ^/product-category/Mens/$1 [L,R]
and for the query string rule you need:
RewriteCond %{QUERY_STRING} ^mens(.*)$
RewriteRUle ^ %{REQUEST_URI}?Mens%1 [L,R]

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]

URL RewriteEngine Internal Server Error

I'm using the following configuration in .htaccess to try to rewrite URLs of the form http://www.mysite.com/subdir/page.php?param=4 to http://www.mysite.com/subdir/page/param/4:
# Turn on the rewrite engine
Options +FollowSymlinks
RewriteEngine on
# Request routing
RewriteRule ^([a-zA-Z_-]*)$ index.php?name=$1 [nc,qsa]
However, I get an Internal Server Error when I visit the page. Is there something wrong with the configuration?
EDIT: I've updated it to the following, but now it does not seem to be doing any rewriting and gives me a 404 when I try to use a URL like http://www.mysite.com/subdir/param/2:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^name=([0-9]+)$ [NC]
RewriteRule ^project-testing/ws/index.php$ /project-testing/ws/name/%1 [R=301,NC,L]
You need to use %{QUERY_STRING} to read the query string of your URL to redirect based on it.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^param=([0-9]+)$ [NC]
RewriteRule ^subdir/page.php$ subdir/page/param/%1 [R=301,NC,L]
Or if you want that accessing:
http://www.mysite.com/subdir/page/param/4
Shows the content of:
http://www.mysite.com/subdir/page.php?param=4
Then it would be like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^subdir/page/([^/]+)/([^/]+)$ subdir/page.php?$1=$2 [NC,L]

Resources