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]
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]
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]
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]
I use the following rule
RewriteRule ^([\w]+)/?([\w]+)? index.php?action=$1
for rewriting
www.mysite.com/123
to
www.mysite.com/index.php?action=123
This needs to remain like this, but there are cases where I also need to rewrite
www.mysite.com/123/abc
to
www.mysite.com/index.php?action=123&example=abc
How can I achieve this? Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?action=$1&example=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?action=$1 [L,QSA]
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^products/([a-zA-Z]+)/([0-9]+)/$ index.php?product=$1&price=$2
This code makes
http://www.example.com/products/computer/1000
into
http://www.example.com/index.php?product=computer&price=1000.
Is it possible to make
http://www.example.com/scriptName/arg1/val1/arg2/val2/arg3/val3
into
http://www.example.com/scriptName.php?arg1=val1&arg2=val2&arg3=val3?
The user should be able to give an unlimited number of arguments. This way one can have /index.php?page=forum&subforum=subforum"e1=postNo1"e2=postNo43 and so on rewrite /index/page/forum/subforum/subforum/quote1/postNo1/quote2/postNo43
How would the .htaccess code look?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/([^/]+)/([^/]+)(.*?)/?$ $1/$4?$2=$3 [L,QSA]
RewriteRule ^([^/]+)/$ $1.php [L]
This will forward a URI of /scriptName/arg1/val1/arg2/val2/arg3/val3 to /scriptName.php?arg3=val3&arg2=val2&arg1=val1