.htaccess url rewrite with variables

I'm trying to make my urls look prettier in a specific subdirectory on my site by using rewrite to change:
www.example.com/sub/file/{some_number}/ internally to:
And I keep getting a 404. I'm already removing the .php extension from my site using an .htaccess file that looks like this:

RewriteEngine on # ## Internally rewrite extensionless file requests to .php files ## # # If the requested URI does not contain a period in the final path-part RewriteCond %{REQUEST_URI} !(\.[^./]+)$ # and if it does not exist as a directory RewriteCond %{REQUEST_FILENAME} !-d # and if it does not exist as a file RewriteCond %{REQUEST_FILENAME} !-f # then add .php to get the actual filename RewriteRule (.*) /$1.php [L] # ## Externally redirect clients directly requesting .html page URIs to extensionless URIs # # If client request header contains html file extension RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP # externally redirect to extensionless URI RewriteRule ^(.+)\.html$ http://www.dirtycoffee.com/$1 [R=301,L] # If client request header contains php file extension RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP # externally redirect to extensionless URI RewriteRule ^(.+)\.php$ http://www.dirtycoffee.com/$1 [R=301,L]

My current attempt is to add a line at the top like:

#Subdirectory rewrite: RewriteRule ^sub/file/([0-9]+)/?$ sub/file?num=$1 [L] # Handle requests for file

I know I must have conflicting rules, but I thought [L] would just stop if the new rule was applied.

-------------Problems Reply------------

Instead of:

RewriteRule ^sub/file/([0-9]+)/?$ sub/file?num=$1 [L]


RewriteRule ^sub/file/([0-9]+)/?$ /sub/file.php?num=$1 [L]

You're correct that [L] will stop processing rules, but that also means that you can't eliminate the .php extension since the rule for that is below this one. Also note the leading slash.

Category:php Views:1 Time:2011-10-19

Related post

  • htaccess url rewrite - multiple variables 2012-03-22

    I am trying to rewrite this url: http://www.sample.com/product_guide&product_name=waht&product_type=dog-clipper to: http://www.sample.com/waht/dog-clipper I am using this htaccess code: RewriteCond %{QUERY_STRING} ^product_guide&product_n

  • after .htaccess url rewrite, cannot perform logoff in some of the url rewrited page 2010-06-08

    Recently, I was doing .htaccess url rewrite, make all my php url into html, in some page, the logout button wont work properly. for example, in page ‘quotedetails/Q9999.html’ (rewrited from ‘quotedetails.php?quoteID=Q9999′), when I click logout butto

  • htaccess url rewriting 2 get vars 2011-10-07

    Ok .htaccess url rewriting.. I really don't get it. I need a rewriterule to server-translate http://domain.com/?list&cat=1 to http://domain.com/list/1/ .. Can't figure out how this exactly works. Who can help :)? Can somebody give me a nice tutor

  • htaccess url rewrite with multiple variables in url 2011-02-08

    I want to make some url rewrite rules on my .htaccess file so that this link: http://myseite.com/index.php?var1=value1&var2=value2 will become : http://myseite.com/var1/value2.html So far I have managed successfully to solve this problem but only

  • htaccess url rewrite confusion about request_uri 2011-11-19

    I'm (sometimes) somehow managing to url rewriting successfully but I want to understand the core of what I'm actually doing. Now, whenever I type http://localhost/admin/shop/ to the browser's address bar, I'd like my htaccess to rewrite the url as ht

  • .htaccess url rewrite with ssl redirection 2010-03-14

    I'm having trouble combining a url query parameter rewrite (fancy-url) with a .htaccess ssl redirection. My .htaccess file is currently: Options +FollowSymLinks Options -Indexes ServerSignature Off RewriteEngine on RewriteBase / # in https: process s

  • .htaccess URL Rewrite Problem (Scripts don't load) 2011-02-26

    I am having a problem with an URL rewrite issue in .htaccess. Here is my rewrite code : RewriteEngine on RewriteBase / RewriteRule ^terms(.*) terms.php [L,nc] RewriteRule ^formgate\/([a-zA-Z0-9]{64,64})$ formgate.php?g=$1 [L,nc] When the page loads i

  • .htaccess url rewrite - remove .php remove www. convert ?id=10 to /10 2011-08-06

    As the title says, I need a quite complex url rewrite mechanism for a web-app as .htaccess rule. I've searched quite a lot now and tried hundred of different rewrite rules. So, basically this is what I need: User goes to: http://www.site.com/product.

  • How to check if .htaccess (url rewrite) works properly 2011-09-05

    Below is the .htaccess file. I need to check if this file is working correctly but I don't know the method to test it. Any suggestion? Options +FollowSymlinks RewriteEngine On RewriteBase /crown/ AddType text/xml .xslt DirectoryIndex index.php <Fi

  • .htaccess URL rewrite (break single entity into two) 2011-10-26

    Have tried several suggestions from this site, Google searching, and other sources to no avail. I would like to have a re-write rule that takes a url like this: http://somesite.com/abc123 and changes it to this: http://somesite.com/abc/123 abc123 is

  • htaccess url rewrite (db access)? 2011-10-31

    I have a web page with the following parameters. http://www.somesite.com/community_details.php?comm_id=233&region_id=2&city_id=40 I would like it changed to this http://www.somesite.com/virginia/fairfax/some_community/ How do I call db to ret

  • .htaccess URL rewriting - pages are opening with URL and without URL rewriting even if URL rewriting rules are present in .htaccess file 2011-12-19

    I need help about URL rewriting for image gallery for site. This is problem, I needed to change hosting so I moved site to another server and there was problem because when it was transfered to that new server site worked without url rewriting, even

  • .htaccess url rewrite code in CodeIgniter 2012-01-05

    My site url is: http://www.thebestincanada.ca/index.php?site/searchOther/restaurant/Victoria I want to rewrite the url as: http://www.thebestincanada.ca/restaurant/Victoria What would be the url rewrite rule for this? I tried: RewriteEngine on Rewrit

  • Frustrating .htaccess URL Rewriting issue 2012-03-18

    I'm working with a client and we just recently moved their website from Godaddy (ew!) to Pair Networks. I've used Pair personally and for clients for many years and have had great experiences with them. Unfortunately for this issue, because it is a s

  • htaccess URL Rewrite not working after 301 redirect 2011-08-17

    I have the following url rewrite: RewriteRule ^info/([^/\.]+)/?$ info.php?page=info&subpage=$1 [L] Originally the parameters were the page id's i.e. 0-10. I have now changed this so the URLs have more meaningful slug names to reflect the content.

  • II7 URL rewrite - retrieving variables from MySQL 2011-10-17

    I am trying to setup IIS-7 URL-rewrite to take userIDs from a database and re-write them to their username. For example: www.website.com/account?id=112233 Needs to rewrite to www.website.com/useraccount It needs to retrieve the username by doing a My

  • .htaccess replace (rewrite) $_GET variables in PHP URL 2011-06-24

    I have a URL that will be something like example.com/index.php?p=test so that the PHP will load the test variable using $_GET['p']. The URL can already be simplified to example.com?p=test; however, I wish to simplify this in my .htaccess to site.com/

  • HTAccess URL Rewrite affect GET variables 2012-04-20

    We’re using wordpress, and we have the following in the .htaccess: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d

  • .htaccess URL rewrite with no query string variables 2010-06-17

    I have to rewrite the following URLs, can someone please suggest the contents of a .htaccess file that will do this. For example: example.com/retrieve_cat.php?subcat=364&c=134 needs to look like: example.com/category/subcategory/ Is it possible t

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.093 (s). 11 q(s)