Htaccess and rewrite/deny - apache

Is there a way to deny access to a file using one URL, but allow access using another?
Example:
The actual URL is www.domain.com/index.php but I want to refuse access using that URL, but I still want to be able to display the file using www.domain.com/index.php/somestring
Is this possble?

Instead of generating the .htaccess with the strings stored in the DB, you would be better off writing the .htaccess file so that it treats "somestring" as a GET variable. You would then check if "somestring" is in your DB and if it is, you show the page. Otherwise, you do a php header redirect.
.htaccess
RewriteRule ^index.php/([^/]*)$ /index.php?id=$1 [L]
In your index.php first, grab the GET variable, check for it's presence in the DB, and if it is present, then show the page. Otherwise, you can use a header redirect to send the user to a different page.
$id = $_GET['id']; // You will probably want to escape this
Then, wrap the entire page in an if statement and only display the page if the id exists in the database.

Related

Specify wufoo redirect url in form field

I want to create a single wufoo form, and embed the form inside my own web pages.
WuFoo has a way to define the redirect URL within their GUI, but I want to make the redirect dynamic based on the REFERER value of where the wufoo data was posted form.
This will allow me to dynamically redirect back to a specific web site based on where the form data was entered.
Does anyone know if there is a way to specify the redirect url in a hiddent form field?
I know that I can create separate forms to accomplish this, but I want all of the entered data to be received in one wufoo form.
There doesn't appear to be any way to access the HTTP_REFERER value in WuFoo's form rules, so I don't think trying to use rules will work.
Apparently there is no way to specify the return url in a form field (according to wufoo tech support).
But you can include hidden fields and use wufoo's rules to return to a URL based on those hidden fields.
In the end, I added code to wordpress's index.php to deal with this.

.htaccess rewrite rule to merge slug and id

I have created a real estate website and on it I want to add some rewrite rule to make urls seo friendly. Mainly I want to do this on property details page. Right now the property details page URL is like this
http://www.my-website.com/property_details.php?id=11&slug=westbourne-grove-serviced-offices
So I am passing the property ID and a Slug text of the property name. This slug is not being used anywhere at the moment, so the property details are going to be fetched only by using the ID.
Now I want to change the URLs to
http://www.my-website.com/property/westbourne-grove-serviced-offices-11
So the slug text comes first and the property id is merged in the end using dash "-". I have no knowledge on creating rewrite rules. Any help will be appreciated.
Thank You
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^property/(.+?)-([0-9]+)/?$ property_details.php?id=$2&slug=$1 [NC,L,QSA]

Rewrite rule for form submit

I am very newbie to this. I have a form that has 4 fields. Field1 - 4 method GET. so when i submit the form The url becomes
mydomain.com/page.php?field1=f1&field2=f2&field3=F3&field4=f4.
I want to change this to
mydomain.com/newPath/f1/f2/F3/f4/
You actually want a redirect then. You would rewrite
domain.com/path/a/b/c/d
to
domain.com/path/?w=a&x=b&y=c&z=d
But if you want the server to direct a request like this
domain.com/path/?w=a&x=b&y=c&z=d
to one like this, you are actually redirecting users.
domain.com/path/a/b/c/d
You want a 301 redirect, because then it will hide the new URL with the ampersands:
This is called clean URLs and you can achieve it with regex that accomodate your need in the htaccess file:
Clean URL htaccess

Friendly url with floating count of form parameters

I have form with checkboxes. Afrer submit url looks like:
www.site.com?mod[]=1&mod[]=2&mod[]=3
How to rewrite url above (apache mod_rewrite) into:
www.site.com/mod:1,2,3
Big problem is that i don't know how many checkboxes will checked
Using just mod_rewrite, I cannot see a way to do this, however, using RewriteMap, you could link to an an external script that would take the query string and return the appropriate new url segments. Then invoke the defined map (program) in your RewriteRule.

Redirect a URL based off it's first character with htaccess

So I have a problem in which I'm attempting to redirect a URL based on whether or not it begins with a certain numbers. I'm needing to redirect a site visitor if the first character of the trailing URL begins with the number "1", then I need to remove the number 1 of the URL and then replace the 1 with a specific directory path.
So here's a specific example to clarify. If the user clicks on (or types in their browser's address bar)
http://www.example.com/1d39g
they would automatically be redirected to
http://www.example.com/product/d39g
Also worth nothing, they individual typing in this URL will be reading it off a label in the mail, they won't always be clicking on a link. I originally had thought of doing this through jQuery, but I thought .htaccess would be the best way to approach this.
Activate the mod alias, then add this into your .htaccess
RedirectMatch /1(.*)$ /product/$1