I Can't make RewriteBase and RewriteRule to work properly - php

My structure is the following:
mywebsite/clubeadv/
Inside that folder I have a file called site.php which receives a parameter id.
So, the physical path would be:
mywebsite/clubeadv/site.php?id=something
But I want it to look like this:
mywebsite/clubeadv/site/something
(where 'something' is my parameter)
HOW DO I CONFIGURE THE .HTACCESS FILE?
I tried the following:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^site/(.*)$ site.php?id=$1
Any help would be appreciated.
Thank you.

Try removing the RewriteBase and placing the .htaccess inside your "clubeadv" folder. If your .htaccess is at the root within the "mywebsite" folder, then you could lave the RewriteBase but use RewriteRule clubeadv/site/(.*)$ clubeadv/site.php?id=$1
Either way, I'm pretty sure the "^site" causes it to look for mywebsite/site/something in your case.

It looks like you want:
RewriteEngine On
RewriteBase /clubeadv/
RewriteRule . site.php?id=%{REQUEST_URI}
That will handle URLs like www.<>.com/clubeadv/abc/edf as site.php?id=/abc/edf.

Apparently the problem was the server configuration. To enable .htaccess files, we had to:
Have the following module loaded:
LoadModule rewrite_module modules/mod_rewrite.so
Enable override for needed websites under 'directory' tag:
AllowOverride All
Thank you to those who answered.

Related

Error on using .htaccess

I'm trying to use my .htaccess file but I still can't figure it out what am I doing wrong.
I only want my domain to be yescpol.com.br, and it always comes like this
My .htaccess is inside the folder "porcelanato" and it has this code:
RewriteEngine on
RewriteBase /porcelanato/
I only want my index.php to turn into yescpol.com.br
What am I doing wrong?
The easiest thing to do would be to change the DocumentRoot in the domain configuration or move your files out of that folder and into the root.
If you want to stick with the rewrite method, you will need to add a rule like this.
RewriteEngine On
RewriteRule ^$ /porcelanato [L]
Add this line to the top of your .htaccess file:
DirectoryIndex index.php
Though if this property is set properly on your apache service in httpd.conf (or whatever is serving your pages) this won't have to be added to your .htaccess file.

php file renaming virtually wamp environment htaccess

Does PHP supports htaccess URL rewriting in Windows - WAMP Environment?
How can I use it?
Below is one example:
My existing file name and URL is like below:
http://localhost/um/api_user_registration.php?FIRSTNAME=first_name&LASTNAME=last_name&USERNAME=user_name&EMAIL=abc#abc.com
Can I use it like below:
http://localhost/um/UserRegistration.mac?FIRSTNAME=first_name&LASTNAME=last_name&USERNAME=user_name&EMAIL=abc#abc.com
In short, I want to access file as UserRegistration.mac instead of api_user_registration.php
Please suggest a way of doing.
URL rewriting is done using mod_rewrite, an apache module. Make sure that it's loaded (probably in httpd.conf) and then add this to the htaccess file in your /um/ folder:
RewriteEngine On
RewriteBase /um/
RewriteRule ^UserRegistration\.mac$ api_user_registration.php [L]
You can try like this:
RewriteEngine on
Options +FollowSymlinks
RewriteBase /yourproject
RewriteRule ^UserRegistration.mac/([^/]+)/(.*) api_user_registration.php?id=$1 [PT]
more info: http://goo.gl/EBzz6t

Subfolders Url rewriting using htaccess

i am working within sub folder of my website and i want to rewrite my urls.
i have never done this before nor have any knowledge of rewriting rules.
I have a file which named show.php which takes parameter id which is any no and then it echo that no on to the screen.
Now this file is in folder name polo.
www.xyz.com/polo/show.php
i want to rewrite
www.xyz.com/polo/show.php?id=10
to
www.xyz.com/polo/id/10
I tried this answer but still its not working.
Subfolders using htaccess
Any help would be appreciated.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(polo)/(id)/([0-9]+)/?$ /$1/show.php?$2=$3 [L,QSA,NC]

URL Rewriting with .HTACCESS not working in php

My URL looks like this:
http://127.0.0.1/website/comments.php?topic_id=16
I want to make it look like this:
http://127.0.0.1/website/comments/my-news-article/16.php
I have applied this
RewriteEngine on
RewriteRule ^comments/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ comments.php?id=$2
I have also turned on Rewrite_module in Apache.
But it's not working.
Always consider the entire URL path. Yours includes /website, so:
RewriteEngine on
RewriteBase /website
RewriteRule ^comments/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ comments.php?id=$2
RewriteBase is used for per-directory directives. Try
RewriteEngine on
RewriteRule ^/website/comments/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ /website/comments.php?topic_id=$2
Works for me. Note that I also changed the query string parameter at the end of the line to "topic_id". Maybe this is another cause of error. If it still fails, check that the configuration is in the right virtual host config.

mod_rewrite to serve a new version of existing files

I have just made a central dynamic script to replace a messy folder full of static files. However, I would like to preserve the old URL's without having to delete those files. Let me give you an example:
I have the following files:
/oldpages/projekt1/index.html
/oldpages/projekt2/index.html
/oldpages/projekt3/index.html
The actual new urls are:
/newscript/script.php?name=projekt1
/newscript/script.php?name=projekt2
/newscript/script.php?name=projekt3
The rewrite rule is:
Options -MultiViews -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^oldpages/([A-Za-z0-9_\-]+)/(index.html)?$ /newscript/script.php?name=$1 [L,QSA]
However, whenever I try to access http://mydomain.com/oldpages/projekt3/index.html it just keeps giving back the old files. After googling, everyone said that multiviews may be the culprit, but apparently, that's not fixing it.
The rule works if the directory doesn't exist on the server, the following works perfectly:
Options -MultiViews -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^newpages/([A-Za-z0-9_\-]+)/(index.html)?$ /newscript/script.php?name=$1 [L,QSA]
And http://mydomain.com/newpages/projekt3/index.html gets the right page.
What am I doing wrong?
Any help would be greatly appreciated.
If a .htaccess in /oldpages has RewriteEngine On, that overrides all rules in the .htaccess in /.

Categories