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]
Related
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]
I'm trying to change the name of domain using htaccess , this is i want :
http://olddomaine.com/subname/* to http://newdomaine.com/*
I'm using this solution , but the page just load without nothing :( :
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} !^olddomaine\.com$
RedirectMatch 301 ^/subname/$ http://newdomaine.com/
#RewriteRule (.*) http://newdomaine.com/$1 [R=301,NC]
#RewriteRule ^subname/(.*) http://newdomaine.com/$1 [R=301,NC]
You are mixing mod-rewrite with mod-alias. Both would work for your required redirects, but you should only use a single method.
The following is using mod-alias:
Options +FollowSymlinks -MultiViews
RedirectPermanent /subname http://newdomain.com/
and the following one is using mod-rewrite:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^subname(?:/(.*))$ http://newdomain.com/$1 [R=301,L]
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]
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]
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]