I have a problem with my .htaccess file, my problem is I have site on localhost and path to it is:
localhost/site/sitename/html/login.php?ref=company
and after uploading to server would be:
www.site-name.com/login.php?ref=asdas
What I needd to do is rewrite ref to looks like this (in both cases):
path_to_site/company/login.php
where company is
$_GET['ref']
For ex. I have this url:
localhost/site/sitename/html/login.php?ref=cola
And I want have this:
localhost/site/sitename/html/cola/login.php
How to do it?
Try this if it works for you:
RewriteCond %{HTTP_HOST} ^(.*)/$login.php$
RewriteRule ^(.*)$ http://www.site-name.com$1 [R=301,L]
I hope I understood what you want correctly. Also check if you have everything enabled and configured on your server correctly.
Look # http://httpd.apache.org/docs/current/mod/mod_rewrite.html for more information if youre using Apache.
Related
I'm trying to change the URL of my website to show only the ID but It seems to not work...
I don't know why.. other commands of RewriteRule work well..
Actually the .htaccess file looks like belove
RewriteEngine On
RewriteRule ^/?([0-9a-zA-Z-]+)/$ article.php?articleId=$1 [L]
I want that it works like this:
Old_URL(to modify):
mywebsite.it/article.php?articleId=15
I want something like this:mywebsite.it/article/15
But the URL remains the same actually: always display this: mywebsite.it/article.php?articleId=15
Thanks in advance to every help :)
An internal rewrite will never change the URL visible in the browser. You are probably looking for an external redirection. Or better the combination of both:
RewriteEngine On
# externally redirect old URL
RewriteCond %{QUERY_STRING} (?:^|&)articleId=(\d+)(?:&|$)
RewriteRule ^/?article/?$ /article/%1 [R=301,L]
# internally rewrite new URL
RewriteRule ^/?article/(\d+)/?$ /article.php?articleId=$1 [END]
Those rules are meant to be implemented on top level. Best in the actual http server's host configuration. If you do not have access to that then a distributed configuration file will work (".htaccess") when located in the host's DOCUMENT_ROOT, but support for that needs to be enabled.
It is a good idea to start out using a R=302 temporary redirection and only change that to a R=301 permanent redirection once you are happy with how things work. That prevents caching issues on the client side.
I store data in text file.
And when user enter in address bar something like
my_syte.com/aaa - (without extension)- I need to file_get_contents aaa.txt file
my_syte.com/bbb - I need to file_get_contents bbb.txt file
Please advise the most powerful way of do it. Apache server.
Thanks
On Apache servers you can use mod-rewrite in .htaccess file:
RewriteEngine on
RewriteRule ^([a-zA-Z]+)$ /$1.txt [L]
if your files can contain - or _ or numbers then use:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ /$1.txt [L]
On nginx servers it's more complicated but some of them works with .htaccess. On other servers there may be entirely different approach. It's hard to help you without more informations.
As you said it's Apache, then use examples above. Either edit or create .htaccess file on your webroot (directory which is accessed by domain). First check if it were there (could be hidden) and if it exists then only edit it (add lines at the top).
If it doesn't exist, then create one by yourself.
Can you please give us some insights about your server? Apache nginx?
In Apache, you can achieve that with url rewriting.
Enable mod_rewrite in apache
Put the following line of code in .htaccess on the same location of my_site.com/
RewriteEngine on
RewriteRule ^/foo$ /foo.txt [PT]
to make it generic
RewriteEngine on
RewriteRule ^/*$ /foo.txt [PT]
Maybe I am wrong in sytax based on your specific server configuration. You need to make the best possible regular expression for this case.
I am trying to run laravel4 on a service that cannot use Apache or nginx.
everything is good till I wanted to use Routes on my project.
I've tried using /index.php/... on the URL but could not make this work.
is there any way to force laravel not to use .htaccess file or any ways to use raw PHP routing?
Try setting the "application.url" option in one of configuration files, probably in app/config/application.php or application/config/application.php:
https://github.com/laravel/laravel/blob/4cb904f44d24f856ec9c1040d2198ed8f009723b/application/config/application.php
Set it to http://127.0.0.1:54007/index.php. Now when laravel creates url it will use this as a root and the final urls should be like http://127.0.0.1:54007/index.php/account/signin.
Also you need to modify PHP Desktop settings so that it uses a fixed port. Edit settings.json file and set it like this:
"web_server": {
"listen_on": ["127.0.0.1", 54007],
In laravel's .htaccess I've found this:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
So it should work fine to add "/index.php" to root url, because this is what apache's mod_rewrite does.
If something doesn't work, take a look at some other files named "url.php", "uri.php".
Let us know if that works.
EDIT.
You may also try setting root url to "index.php", without the "http://". This way it wouldn't be required to set a fixed web server port.
UPDATE
There was a bug in Mongoose web server in PHP Desktop, that prevented urls like "index.php/company/5" from working properly. See the __fix_mongoose_env_variables() php function in Issue 137 that fixes it:
https://code.google.com/p/phpdesktop/issues/detail?id=137
I am having trouble with the RewriteRule. I have created a pretty URL for my search page where it posts to itself to query the results. However the $_GET['type'] variable is not being sent to the page. This works perfectly fine on my local WAMP server but does not return a result on my Live hosted server.
e.g. http://..com/search/searchType/ SearchType being the $_GET['type'] data I am sending to the page.
My .HTACCESS is as follows
RewriteEngine On
RewriteRule ^property/(.*)/(.*)/([0-9]+)/$ view_property.php?type=$1&id=$3 [L]
RewriteRule ^search/(.*)/ search.php?type=$1 [L]
The problem is because there is a conflict with the file name search.php, which broke the RewriteRule which started with the text 'search'.
After discovering this and doing more research I found that including Options -MultiViews which disables the mod_negotiation MultiViews.
This must have been enabled on my Live hosted server and disabled on my local host. I will find out and update shortly.
Another fix is to rename the RewriteRule URL to something other than ^search/ or any other name that currently exists as another file to remove this conflict.
We have two sites, and we've just now made an in-house development server that we want to have both sites on. What I want to accomplish is to have an .htaccess in each of the site folders that prepends the development URL of the site. For example, where they simply have a header(location: /folder/whatever.php), the files should actually go to thesite/folder/whatever.php.
Currently what happens is (for example) they'll go to 192.168.x.x/folder/whatever.php
If I understood correctly and what you want is to redirect 192.168.x.x/folder/whatever.php to thesite/folder/whatever.php, you could use this:
RewriteCond %{HTTP_HOST} !^thesite.com$
RewriteRule ^(.*)$ http://thesite.com/$1 [R=301,L]