Sorry for my poor English.
I'm developing a Prestashop module to list services in a block on the Front-end. The module is complete but this uses ugly URLs like "http://www.mysite.com/modules/servicescatalog/showservicedata.php?srvId=1"
The client of this module wrote to me to make this URL SEO Friendly, like "http://www.mysite.com/modules/servicescatalog/showservicedata/service-1"
Searching in Google I think the the solution is to implement a Front Controller but I don't know how to manage this. Does anyone know how to implement ???
Just make a new .htaccess file inside your module folder
.htacces example
<IfModule mod_rewrite.c>
# URL rewriting module activation
RewriteEngine on
RewriteRule ^showservicedata/service-([0-9]+)$ showservicedata.php?srvId=$1 [L]
</IfModule>
If you want to make SEO url your module, then go to Preference tab > SEO & URL and the add new. Set up the module with what you want.
Take a look here. It has detailed instructions on adding a custom front controller.
https://www.prestashop.com/forums/topic/342774-add-custom-php-page-prestashop-16/
Related
I have developed a PHP application and I want to rewrite the URLs to make it cleaner,
I have multiple pages, each page can have 0 or multiple GET variables,
Example of what I want to achieve:
index.php -> /
/index.php?var1=aaa&var2=bbb&var3=ccc -> /var1/aaa/var2/bbb/var3/ccc
/product.php?var4=ddd&var5=eee -> /product/var4/ddd/var5/eee
/products-list.php -> /products-list/
etc...
Can anyone help me with a full .htaccess file to achieve this result?
And is there a way to make the PHP read the GET params or do I need to add a function to create a $_GET array from the URL on each page?
Thank you.
These simple rules will rewrite the examples you give in the question:
RewriteEngine on
RewriteEngine ^/?products-list/?$ /products-list.php [QSA,END]
RewriteRule ^/?product/([^/+])/([^/+])/([^/+])/([^/+])/?$ /product.php?$1=$2&$3=$4 [QSA,END]
RewriteRule ^/?([^/+])/([^/+])/([^/+])/([^/+])/([^/+])/([^/+])/?$ /index.php?$1=$2&$3=$4&$5=$6 [QSA,END]
You might have to add some conditions to prevent interference with other rules or rewriting loops. But that is nothing we can know without insight into your specific situation and setup.
I have this single page app made using AngularJS and it resides in the document root: http://example.com/
The API that Angular interacts with is created with CakePHP and is located in a subfolder called api. It's accessed via http://example.com/api/xxx.
Apart from acting as an API, the CakePHP application also has an administration backend. In the current URL structure, it's accessible via http://example.com/api/admin. To make it look neater I want users to be able to access it via http://example.com/admin.
What htaccess and IIS rule will I need to achieve this? I'll be testing on both platforms.
Thank you.
You mean http://example.com/admin I assume.
In htaccess you can do it like this:
RewriteEngine On
RewriteRule ^api/admin(/?$|/.+) /admin$1 [QSA,L]
Demo here: http://htaccess.mwl.be?share=d8c07577-d6fb-501d-8e32-403531d471a1
May be a noob question but I'm just starting playing around with apache and have not found a precise answer yet.
I am setting up a web app using url-rewriting massively, to show nice urls like [mywebsite.com/product/x] instead of [mywebsite.com/app/controllers/product.php?id=x].
However, I can still access the required page by typing the url [mywebsite.com/app/controllers/product.php?id=x]. I'd like to make it not possible, ie. redirect people to an error page if they do so, and allow them to access this page with the "rewritten" syntax only.
What would be the easiest way to do that? And do you think it is a necessary measure to secure an app?
In your PHP file, examine the $_SERVER['REQUEST_URI'] and ensure it is being accessed the way you want it to be.
There is no reason why this should be a security issue.
RewriteCond %{REDIRECT_URL} ! ^/app/controllers/product.php$
RewriteRule ^app/controllers/product.php$ /product/x [R,L]
RewriteRule ^product/(.*)$ /app/controllers/product.php?id=$1 [L]
The first rule will redirect any request to /app/controllers/product.php with no REDIRECT_URL variable set to the clean url. The Rewrite (last rule) will set this variable when calling the real page and won't be redirected.
How would I go about making my site use organic urls (like http://www.mysite.com/aboutus) - i don't want to use a CMS - my site is powered from index.php is there anyway of getting the text after the / so that I can select that page from the database? I'd rather not do /?aboutus
Thank you :D
You have to use a URL Rewrite engine.
Apache HTTP Server provides URL rewriting through the mod_rewrite module. You may want to check out these articles to get started:
Added Bytes: URL Rewriting for Beginners
Apache: URL Rewriting Guide
You can use mod_rewrite as others suggested. For example the following will map http://my.site.com/page to http://my.site.com/index.php?module=page
RewriteEngine on
RewriteRule ^/([a-z0-9]+)/?$ /index.php?module=$1 [L,QSA]
If you would like to use RESTful URLs throughout your site, here is a handy reference from microformats.org: rest/urls
I am new to URL rewriting and I have an .htaccess file that looks like this:
RewriteEngine On
RewriteRule /*\.(css|js|gif|png|jpe?g)$ - [NC,L]
RewriteRule "^(.*)$" "www/index.php?_url=$1" [QSA,L]
Does this code just rewrite the code internally, or is it supposed to change to URL in the address bar? As of now it does not change the address bar, and I'm not really sure yet but I am thinking that I will probably want the option to do so for bookmarking purposes. So if there is a way could you please let me know or direct me to a pretty noob friendly guide on URL rewriting where I can figure it out on my own because I haven't been able to find one.
Thanks for the help!
As it stands, it will just do an internal rewrite. To redirect the user (thereby changing their address bar), add R to the flags (e.g. [NC,R,L] or [R,QSA,L])
URL rewriting is completely server-side (unless you do a redirect). The client (and thus their address bar) will not know what the server is doing with the URL.
Here's a good beginner tutorial that explains URL rewriting and goes through progressively more complex examples.