Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
This is hard to explain, better with an example...
I have this valid url: www.sitetoautenthicate.com/portal/index.php.
To access this page, I want to mask the url to www.sitetoautenthicate.com/portal/myportal/index.php where myportal has to be authenticated (exists in database) through an external API (ajax post).
I also want to forbid access to www.sitetoautenthicate.com and www.sitetoautenthicate.com/portal/
I think this can be done only with .htaccess
I also want to forbid access to www.sitetoautenthicate.com and www.sitetoautenthicate.com/portal/
Try this rule in in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.sitetoautenthicate\.com$ [NC]
RewriteRule ^(portal)?/?$ - [F,NC]
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I currently have the page '/tags.php?id=foo', and want it to display in the browser as '/tags/foo'. How might I do this with the .htaccess file?
EDIT
I've tried the solution given below and read up a little bit on Regex, but it's still not quite working how I need it to - is it possible once using the .htaccess mod_rewrite to still derive the $_GET data from the URL to use in code?
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^tags/([^/]+)/?$ /tags.php?id=$1 [L,QSA]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Current API usage: http://api.mydomain.com/v1/names?gender={gender}&age={age}
What I want usage to be: http://api.mydomain.com/v1/names/{gender}/{age}
Can I use .htaccess to rewrite this URL?
Assuming both parameters are numeric:
RewriteEngine on
RewriteRule /v1/names/([0-9]+)/([0-9]+) /v1/names?gender=$1&age=$2 [L]
If they can also contain alphanumeric characters replace both instances of [0-9]+ for example with [A-Za-z0-9]+ or whatever fits the requirement.
Apart from that I'd recommend doing this in PHP for more flexibility.
RewriteEngine on
RewriteRule /?v1/names/(.+)/(.+) /v1/names?gender=$1&age=$2 [L]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to make a url to look like example.com/users/user?
I do not use a framework and I write procedural PHP code.
You need somthing like this? Not clear what is your requirement. Check this blog for more
Rewriting example.com/user.php?username=xyz to example.com/xyz
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
Refer htaccess2 tricks
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following URL:
www.mysite/apage.php?product_id=295-Product-name-in-a-color
I would like the following:
www.mysite/id=295-Product-name-in-color
The product name and colour are triggered from a different page.
I can redirect the actual apage.php using .htaccess however I lose everything else and it won't find my page.
Any help welcome
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^id=([^/]+)-(.+)$ /apage.php?product_id=$1-$2 [L,QSA,NC]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Improve this question
I have a page "page.php" on my site "www.mysite.com". "page.php" is a profile page for users on my website. Users profile can be accessed like this: "http://www.mysite.com/page.php?user=rehan". Using htaccess, I would like to rewrite the link to: "http://www.mysite.com/rehan". How can I achieve this?
Thanks in advance,
Rehan.
You can try this
RewriteEngine on
RewriteBase /
RewriteRule ^([^//]+)$ page.php?user=$1 [QSA,L]
for that you have to use :
`
RewriteEngine on
RewriteRule ^([^//]+)$ page.php?user=$1 [QSA,L]`
but on some servers you have to add :
RewriteBase /