send id via url but hidden - html

I have an html link:
Link
I formatted the link destination with a htaccess file:
RewriteRule ^destination$ index.php?content=destination [L,NC,QSA]
The question is: How can I give a ID via URL to the destination?
the full link will be index.php?content=destination?ID=x
X will be a dynamic number
but I would like to show this in the url - it should be invisible.
But I don't know how I have to modify the rewriteRule to realize it.

Although not a pretty solution and it obviously comes with flaws, you could always use cookies.
set a cookie in PHP:
setcookie("page_id","987987");
and look for it in htaccess
RewriteCond %{HTTP_COOKIE} ^page_id=([0-9]*)$ [NC]
RewriteRule ^destination$ index.php?content=destination&id=%1 [L,NC,QSA]

Related

Make url so that I can also accept extra parameter in .htaccess

I have goggling all around but not able to find the right solution.
I have a simple HTML site that contains only HTML files(.html extension) like pricing.html,contact-us.html etc.
I want to make url so that it accept integer as a parameter like this
Currently: http://www.amznhosting.com/pricing.html
I want to make url so that I can also accept extra parameter like this:
http://www.amznhosting.com/pricing.html/2
This is what I did so far in .htaccess
RewriteRule ^(.*)$ pricing.html?params=$1 [L,QSA]
Its working but css,js and images are not getting load.
Anyone having any idea?
You can use the following rule :
RewriteEngine on
RewriteRule ^(.+)\.html/(.+)$ /$1.html?params=$2 [NC,L]
This will rewrite /file.html/path to /file.html?params=path .

htaccess redirection loop issue

I have a static website that has several html pages. In order to not hide .html extensions from url, we have following rules in htaccess for each url:
RewriteRule ^website-development$ website-development.html
This works fine in that if you open site.com/website-development, it actually opens the website-development.html file but in url it does not show the .html extension.
Now, we need to redirect(or hide) .html urls to their corresponding urls without .html e.g. if someone opens site.com/website-development.html in their browser, the url should be shown as site.com/website-development.
To do this, I added following rule:
RewriteRule ^(.*)\.html$ /$1 [L,R]
But doing this results in indefinite redirection and so the browser just keeps redirecting and never renders the actual page. Can you please suggest how I can redirect both site.com/website-development and site.com/website-development.html to site.com/website-development (which actually is an html file - website-development.html ). Thanks.
Yes indeed, this rule will cause a redirect loop:
RewriteRule ^(.*)\.html$ /$1 [L,R]
It is due to the fact your REQUEST_URI is adding and removing .html in 2 different rules and mod_rewrite runs in a loop.
You can use this rule instead based on a RewriteCond that uses THE_REQUEST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules. Example value of this variable is GET /index.php?id=123 HTTP/1.1

How to show index of page with htaccess?

I'm new to hosting and I'm trying to get a basic "index of" page to show.
I have an address ie: www.mydomain.com/files
I just have some zip files in that location that I'd like to show and allow users to download but not sure how to do this. At the moment I just get a FORBIDDEN page.
Create an .htaccess file and put
Options +Indexes
In it.
try this :
Rewritecond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Link to index page of website

Is there a way to link to the index page of a website without specifying the name of the index page or the full website URL?
I have this:
Home
But when I click the link, my address bar shows:
mydomain.com/index.html
I would like it to show:
mydomain.com
Can I do that without putting the full URL (mydomain.com) in the href? If so, how?
For future viewers, I also found this question helpful.
You can just do this:
Home
Any href preceded by a slash is relative the root directory.
It should be noted that when viewing a webpage from a local hard drive in a browser, this will cause the link not to function.
I know this post is old and has an answer. But here is my contribution that also supports index that is not exactly in the root directory
to goto
mydomain.com/index.html
without index.html showing in address bar
Home
this will always point to mydomain.com no matter where the directory your file was saved to.
to point to the index in a directory use this:
Home
this will point to mydomain.com/subdir for mydomain.com/subdir/index.html while the accepted answer will always point to mydomain.com (and this is not always the desired action)
Create a ".htaccess" file and upload to your host public folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.yourwebsite.com.ph/ [R=301,L]
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
</IfModule>

How can I redirect main domain to another domain but not include sub domains in the redirect - htaccess

I have the .co.uk and .com for for my domain and I currently have the .co.uk set-up to redirect to the .com. Whilst this works, I now need to refine this redirect a little so that it does not include any subdomains. So www.domainname.co.uk will redirect to another but subdomain.domainname.co.uk will not redirect.
Is this possible and if so how do I do it?
You may want to take a look at RewriteCond, something like this:
RewriteCond %{HTTP_HOST} www.\mysite\.co\.uk [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301]
For more in-detail information about RewriteCond: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond