.htaccess - point dir1/dir2/index.php to /dir1/page.php [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'd like to set my Apache server up so that when someone visits, say, site.com/kittens/ (or site.com/kittnes/index.php), they would actually get to view site.com/certainpage.php. Of course I could copy certainpage.php to /kittens/ and rename it index.php, but it seems like a really lame way to do it.
Any help? I feel like this shouldn't be something too complex.

You can use a rewrite rule to keep the URL the same but swap the contents out for that of another file like so:
RewriteEngine On
RewriteRule ^kittens/(index\.php)?$ /certainpage.php [L]

Related

PHP Content not loaded from MySql, but no error [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am working on some sort of blogging platform in php with a nice material design lite frontend. However I have a page that dynamically loads the content, it works fine in the root directory, but not in my admin directory. I hope you can spot some kind of error/typo in my code, I know the error is in the menu-start file, since disabling it enables loading.
Here is the page that loads the code
and here is the menu-start page
If you need any other code, please ask
You're using relative links for include, which will mess up when you start changing directories. Use a pseudo-absolute path with DOCUMENT_ROOT. Be sure to use this for all of your includes.
<?php include $_SERVER['DOCUMENT_ROOT'].'/menu-start.php'; ?>

How do I use URL directories as variables? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm wondering how sites like Pastebin and Twitter pass (what I assume to be) variables via the URL.
For example, take a Pastebin URL. It has the format of http://www.pastebin.com/<PASTE_UID>. I'm wondering how they parse the UID without the server trying to treat it like an actual page. I can't imagine they generate individual files for each post.
I know this is most likely a combination of mod_rewrite and parsing the variable from the URL on the backend to extract the variable, but I'm at a loss on how to do it.
As you said, you can use apache mod_rewrite, i.e.:
Create an .htaccess file on the root of your website with the following content:
RewriteEngine on
RewriteRule ^uid/(.*)$ /uid.php?uid=$1 [NC]
If, for example, the url is http://yoursite.com/uid/123456, apache will send the value 123456 via $_GET request to uid.php, you can get the uid value using:
<?php
if(!empty($_GET['uid'])){
$uid = $_GET['uid'];
//123456
}
?>

Domain name getting with number link: domain.com:399 [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
While redirecting one page to another page using h t access getting attached extra number to domain
e.g: "domain.com:399" here i need to remove ":399" form domain how to do this?
something like this might work:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/a
RewriteRule (.*) http://[yourdomain]/b/link.php

Code for set the url as usernameq [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I use a code to set the URL as:
http://domainname.com/user
The problem is that I use some masks in my .htaccess, so what we see in the URL is not always the real path of the file.
What I need is to get the URL, what is written in the URL, nothing more and nothing less—the full URL.
I need to get how it appears in the Navigation Bar in the web browser, and not the real path of the file on the server.
You need to simple check in PHP what's the value of $_SERVER['REQUEST_URI']
or substr($_SERVER['REQUEST_URI'],1) if you want to remove leading slash

Need help for .htaccess from OOP php to CodeIgniter [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I shifted to CodeIgntier from OOP php and there are lot of links which are not working, for example this old link
http://www.flowersentiments.com/Occassional-Special/29/Birthday/122/
should actually be redirected to
http://www.flowersentiments.com/products/Occassional/29/Birthday-Gifts/122/
I have tried all methods to redirect it using .htaccess. but It just doesn't work.
Please help
In the htaccess file in your document root, you need to add your redirect rules before any of the other rules that yo uhave there for CodeIgniter:
RewriteEngine On
RewriteRule ^Occassional-Special/([0-9]+)/Birthday/([0-9]+)/$ /products/Occassional/$1/Birthday-Gifts/$2/ [L,R=301]
You'll need to do the same thing (or something similar) for all of your other broken links.

Categories